MySQL :: MySQL 8.0 Reference Manual :: 13.1.4 Floating-Point Types (Approximate Value) (original) (raw)
13.1.4 Floating-Point Types (Approximate Value) - FLOAT, DOUBLE
The FLOAT
and DOUBLE
types represent approximate numeric data values. MySQL uses four bytes for single-precision values and eight bytes for double-precision values.
For FLOAT
, the SQL standard permits an optional specification of the precision (but not the range of the exponent) in bits following the keywordFLOAT
in parentheses, that is,FLOAT(p). MySQL also supports this optional precision specification, but the precision value inFLOAT(p) 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.
MySQL permits a nonstandard syntax:FLOAT(_`M`_,_`D`_)
orREAL(_`M`_,_`D`_)
or DOUBLE PRECISION(_`M`_,_`D`_)
. Here,(_`M`_,_`D`_)
means than values can be stored with up to_M
_ digits in total, of which_D
_ digits may be after the decimal point. For example, a column defined asFLOAT(7,4)
is displayed as-999.9999
. MySQL performs rounding when storing values, so if you insert 999.00009
into a FLOAT(7,4)
column, the approximate result is 999.0001
.
As of MySQL 8.0.17, the nonstandardFLOAT(_`M`_,_`D`_)
andDOUBLE(_`M`_,_`D`_)
syntax is deprecated and you should expect support for it to be removed in a future version of MySQL.
Because floating-point values are approximate and not stored as exact values, attempts to treat them as exact in comparisons may lead to problems. They are also subject to platform or implementation dependencies. For more information, seeSection B.3.4.8, “Problems with Floating-Point Values”.
For maximum portability, code requiring storage of approximate numeric data values should use FLOAT
orDOUBLE PRECISION
with no specification of precision or number of digits.