Estimated time: FLOAT, DOUBLE, or DECIMAL

MySQL version 5.1.6 is currently in use.

This is my first compilation in the real world, and so far I have really enjoyed it; however, I am now stuck in a decision about a field data type and hope someone can figure it out for me.

I essentially have 10 fields that are different test results. Numbers range from -100 to 100 and can have a decimal number with one spot after the actual point.

For example, -5.1, 0, 1, 16.3, 99.2 and 100 are all possible data. From what I read, you should use DECIMAL for the things that we usually measure and accurate (which they are), while FLOAT and DOUBLE are approximations that I really don't want (although I'm sure at this level, the approximation is very small if it exists at all).

If I use DECIMAL, should I include a space for '-' at the beginning, if used? IE, would I use DECIMAL (4.1) or DECIMAL (5.1), or am I here? Maybe I overdid it a bit.

+7
source share
2 answers

The negative character is NOT counted as a digit in your calculation, so DECIMAL (4.1) should be in order.

Edit: this also looks like the right field to use for your purposes. Give it a try!

+4
source

DECIMAL(4,1) will be enough, the digit of the sign does not need to be included.

Additional information: http://dev.mysql.com/doc/refman/5.1/en/precision-math-decimal-changes.html

For example, the DECIMAL(3,0) column supports a range of -999 to 999

Decimal is really the best option for your needs. Float and Double can give you ugly numbers (e.g. 0.2 cannot be represented as float, you get 0.19999999)

+6
source

All Articles