1

I have a current db table called scores that has 2 columns user_score and approved_score which are both Integer.

After initial launch we have decided to make things more exact by add a decimal to a score. So instead of getting a 10 you could get a 10.40 or a 10.47 ect. I am just curious on:

  • Should I change it to a decimal or a float based on us needing 2 decimal points with trailing 0. So: $table-> decimal('user_score', 8, 2)->change();
  • Will that mess up data in there already? Like will a score of 123 stay 123? We rank based on score so the higher the better.
3
  • Just a thought here, but you could keep it as an integer and then divide by 100 when displaying the scores to reflect it as a decimal. That's how Stripe stores transactions amounts, as a whole number, then it's up to the application's display logic to convert to a decimal format. Commented Mar 6, 2018 at 20:49
  • The trouble is there are scores already in there so I dont want to have a new score of 1000 (which would equal 10 in your solution) be better than a current score of 10 Commented Mar 6, 2018 at 20:54
  • @btl if you want to add that as an answer I will accept Commented Mar 6, 2018 at 21:41

1 Answer 1

1

A float would be more appropriate in this case, it doesn't sound like you need a high number of precision points after the decimal place. The data should not be impacted by changing the column type, so long as your values are not currently larger than (8,2).

Also, updating your existing data if you kept the column as an integer would be trivial as all you would need to do is UPDATE column SET column=column*100.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.