标题: mysql 字段类型保存小数和整数 [打印本页] 作者: awagink 时间: 2020-11-21 19:32 标题: mysql 字段类型保存小数和整数 mysql float double类型
1.float类型
float列类型默认长度查不到结果,必须指定精度,
比如 num float, insert into table (num) values (0.12); select * from table where num=0.12的话,empty set。
num float(9,7), insert into table (num) values (0.12); select * from table where num=0.12的话会查到这条记录。
mysql> insert into tt(num) values(234563.9);
Query OK, 1 row affected (0.00 sec) www.2cto.com
mysql> select * from tt;
+------------+
| num |
+------------+
| 234563.900 |
+------------+
1 row in set (0.00 sec)
mysql> insert into tt(num) values(2345623.2);
ERROR 1264 (22003): Out of range value for column 'num' at row 1
mysql> insert into tt(num) values(234563.2);
Query OK, 1 row affected (0.00 sec)
mysql> select * from tt;
+------------+
| num |
+------------+
| 234563.900 |
| 234563.200 |
+------------+
2 rows in set (0.00 sec)