When using decimal in MySQL, does a value of (5,3) make it so the max number is 99.999? If not how do I specify that? My number is for currency so I need to use decimal, but it should not go over 99 and it must have 3 decimal places.
When using decimal in MySQL, does a value of (5,3) make it so the
Share
decimal (5,3)is the standard SQL way to define a field with a range of-99.999 .. 99.999.Note that with MySQL, if you attempt to insert a value that is out of range, MySQL will automatically truncate the value to the nearest boundary value (in this case, either 99.999 or -99.999) without throwing an error.
Added
In this case, there will be a maximum of
5digits of data stored, with exactly3digits to the right of the decimal point. If you insert a number like1.23it will be stored as1.230; likewise1will be stored as1.000. If you insert12.3456it will be rounded up to12.346; if you insert12.0001it will be rounded down to12.000.When the column is returned to your program, the exact representation will depend upon how your database API maps a decimal data type. If it maps to an integer, you’ll lose the decimal fraction; if it maps to a floating point number (float, double), you may lose precision; if it maps to a Decimal (C#/Java) then you’ll get an exact representation, as long as your value is within the bounds of the datatype.