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>原因為:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM