MySQL的float和double取精度问题

一、引用刚师兄的一个例子,这是他在他机器上执行的结果
二、我在我电脑上测试如下:
mysql> desc t12;
+-------+---------------+------+-----+---------+-------+
| Field | Type          | Null | Key | Default | Extra |
+-------+---------------+------+-----+---------+-------+
| c1    | float(10,2)   | YES  |     | NULL    |       |
| c3    | decimal(10,2) | YES  |     | NULL    |       |
+-------+---------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> desc t13;
+-------+---------------+------+-----+---------+-------+
| Field | Type          | Null | Key | Default | Extra |
+-------+---------------+------+-----+---------+-------+
| c1    | double(10,2)  | YES  |     | NULL    |       |
| c3    | decimal(10,2) | YES  |     | NULL    |       |
+-------+---------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> truncate table t12;
Query OK, 0 rows affected (0.06 sec)

mysql> truncate table t13;
Query OK, 0 rows affected (0.05 sec)

mysql> insert into t12 values(1234567.23,1234567.23);
Query OK, 1 row affected (0.01 sec)

mysql> insert into t13 values(1234567.23,1234567.23);
Query OK, 1 row affected (0.01 sec)

mysql> select * from t12;
+------------+------------+
| c1         | c3         |
+------------+------------+
| 1234567.25 | 1234567.23 |
+------------+------------+
1 row in set (0.00 sec)

mysql> select * from t13;
+------------+------------+
| c1         | c3         |
+------------+------------+
| 1234567.23 | 1234567.23 |
+------------+------------+
1 row in set (0.00 sec)

三、查询<深入浅出MySQL>原因为:

 
posted @ 2016-03-08 17:42  arun_yh  阅读(8236)  评论(0编辑  收藏  举报