#为了说明问题,摘了官当的部分内容,关于更详细的介绍请直接查看官当。12.2.3 Floating-Point Types (Approximate Value) - FLOAT, DOUBLE#可以看到标题已经指出 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. 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.5.5.8, “Problems with Floating-Point Values因为Float、Double存储的是一个近似值而不是确切的值,试图使用它们存储一个确切的值可以会导致问题。它们依赖于不同平台和不同实现方式,而官当在章节Section B.5.5.8, “Problems with Floating-Point Values中举例说明了此问题参考:http://dev.mysql.com/doc/refman/5.7/en/floating-point-types.html
“Problems with Floating-Point Values”
B.5.4.8 Problems with Floating-Point ValuesFloating-point numbers sometimes cause confusion because they are approximate and not stored as exact values. A floating-point value as written in an SQL statement may not be the same as the value represented internally. Attempts to treat floating-point values as exact in comparisons may lead to problems. They are also subject to platform or implementation dependencies. The FLOAT and DOUBLE data types are subject to these issues. For DECIMALcolumns, MySQL performs operations with a precision of 65 decimal digits, which should solve most common inaccuracy problems.由于浮点数存储的是近似值而不是确切的值,某些时候可能导致混乱。一个浮点数值在SQL语句作为内部表示的值可能不同。试图使用float、double来存储确切的值可能会出现问题,他们也依赖不同平台和实现方式。而对应DECIMAL类型,MySQL作为65位精度进行操作,可以解决此类精度问题。
11.2.2 Fixed-Point Types (Exact Value) - DECIMAL, NUMERICThe DECIMAL and NUMERIC types store exact numeric data values. These types are used when itis important to preserve exact precision, for example with monetary data. In MySQL, NUMERIC isimplemented as DECIMAL。DECIMAL和NUMBERIC存储的是确切的数值,使用它们可以保证精确度,例如用于存储金额数据。在MySQL中,NUMBERIC和DECIMAL以同样的类型实现。