views:

1471

answers:

2

In my database, I would like to store a decimal score. A score can have a value from 0 to 10, and values in between, such as 2.3 or 9.4.

I recently learned that int only stores whole numbers and not decimals. I found out that you could use either double or decimal, but what I would like to know is if there is any difference at all?

I'm currently using decimal.

+5  A: 

Decimals are more precise, doubles are more efficient, usually.

With decimal you can set how many digits you want to use before and after the decimal point.
Edit: You can set digit count for decimal and double, my bad.

Decimals are better for things like money calculations where exactitude is absolutely necessary. Doubles are better suited for your specific case where the exactitude of the score is not critical.

See the overview of numeric types in the MySQL documentation for more information.

David Thibault
Thank you, that's very helpful. :)
different
+1  A: 

Why not use INT and let the Score go from 0 to 100? Let the application display the score divided by ten.

This rids you of the decimal places / rounding errors problem.

Tomalak
Given that the score is a fixed number once submitted (and not calculated on the fly), it shouldn't need to be processed again before it is sent to the client.Good thinking though.
different