11.1.4 Floating-Point Types (Approximate Value)浮点类型(近似值) - FLOAT, DOUBLE

The FLOAT and DOUBLE types represent approximate numeric data values. FLOATDOUBLE类型表示近似的数字数据值。MySQL uses four bytes for single-precision values and eight bytes for double-precision values.MySQL使用4个字节表示单精度值,8个字节表示双精度值。

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; ; that is, FLOAT(p). 对于FLOAT,SQL标准允许在关键字FLOAT之后的括号中指定一个可选的精度(但不是指数的范围);也就是说,FLOAT(p)MySQL also supports this optional precision specification, but the precision value in FLOAT(p) is used only to determine storage size. MySQL也支持这个可选的精度规范,但是FLOAT(p)中的精度值仅用于确定存储大小。A precision from 0 to 23 results in a 4-byte single-precision FLOAT column. 从0到23的精度将产生一个4字节的单精度FLOAT列。A precision from 24 to 53 results in an 8-byte double-precision DOUBLE column.从24到53的精度产生一个8字节的双精度DOUBLE列。

MySQL permits a nonstandard syntax: FLOAT(M,D) or REAL(M,D) or DOUBLE PRECISION(M,D). MySQL允许非标准的语法:FLOAT(M,D)REAL(M,)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. 此处,(M,D)表示可存储的数值最多为M位,其中D位可能在小数点之后。For example, a column defined as FLOAT(7,4) is displayed as -999.9999. 例如,定义为FLOAT(7,4)的列显示为-999.9999MySQL performs rounding when storing values, so if you insert 999.00009 into a FLOAT(7,4) column, the approximate result is 999.0001.MySQL在存储值时执行舍入,因此如果将999.00009插入FLOAT(7,4)列,则近似结果为999.0001

As of MySQL 8.0.17, the nonstandard FLOAT(M,D) and DOUBLE(M,D) syntax is deprecated and you should expect support for it to be removed in a future version of MySQL.从MySQL8.0.17开始,非标准的FLOAT(M,D)DOUBLE(M,D)语法就被弃用了,您应该希望在将来的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, see Section B.3.4.8, “Problems with Floating-Point Values”有关详细信息,请参阅第B.3.4.8节,“浮点值问题”

For maximum portability, code requiring storage of approximate numeric data values should use FLOAT or DOUBLE PRECISION with no specification of precision or number of digits.为了最大限度地提高可移植性,需要存储近似数字数据值的代码应使用FLOATDOUBLE PRECISION,不指定精度或位数。