Search code examples
mysqlfloating-pointlimitdigitsmaxlength

how many digits in FLOAT?


I've looked all over and can't find this answer.

How many actual digits are there for a MySQL FLOAT?

I know (think?) that it truncates what's in excess of the FLOAT's 4 byte limit, but what exactly is that?


Solution

  • From the manual (emphasis mine):

    For FLOAT, the SQL standard permits an optional specification of the precision (but not the range of the exponent) in bits following the keyword FLOAT in parentheses. MySQL also supports this optional precision specification, but the precision value is used only to determine storage size. A precision from 0 to 23 results in a 4-byte single-precision FLOAT column. A precision from 24 to 53 results in an 8-byte double-precision DOUBLE column.

    So up to 23 bits of precision for the mantissa can be stored in a FLOAT, which is equivalent to about 7 decimal digits because 2^23 ~ 10^7 (8,388,608 vs 10,000,000). I tested it here. You can see that 12 decimal digits are returned, of which only the first 7 are really accurate.