我以为我想补充我自己的例子,帮助我使用值看出区别1.3
添加或与另一个相乘时float
,decimal
和double
。
1.3
float添加到1.3
以下不同类型:
|float | double | decimal |
+-------------------+------------+-----+
|2.5999999046325684 | 2.6 | 2.60000 |
1.3
float MULTIPLIED by 1.3
的不同类型:
| float | double | decimal |
+--------------------+--------------------+--------------+
| 1.6899998760223411 | 1.6900000000000002 | 1.6900000000 |
这是使用MySQL 6.7
查询:
SELECT
float_1 + float_2 as 'float add',
double_1 + double_2 as 'double add',
decimal_1 + decimal_2 as 'decimal add',
float_1 * float_2 as 'float multiply',
double_1 * double_2 as 'double multiply',
decimal_1 * decimal_2 as 'decimal multiply'
FROM numerics
创建表并插入数据:
CREATE TABLE `numerics` (
`float_1` float DEFAULT NULL,
`float_2` float DEFAULT NULL,
`double_1` double DEFAULT NULL,
`double_2` double DEFAULT NULL,
`decimal_1` decimal(10,5) DEFAULT NULL,
`decimal_2` decimal(10,5) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `_numerics`
(
`float_1`,
`float_2`,
`double_1`,
`double_2`,
`decimal_1`,
`decimal_2`
)
VALUES
(
1.3,
1.3,
1.3,
1.3,
1.30000,
1.30000
);