float类型在使用的时候应该注意些什么呢。直接设置成float,默认的是几位整数与几位小数??
mysql> create table test(id float,id2 float(12,4));
Query OK, 0 rows affected (0.01 sec)mysql> insert into test values(123456.2341,2342334,5234);
ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql> insert into test values(123456.2341,234233.5234);
Query OK, 1 row affected (0.00 sec)mysql> select * from test;
+--------+-------------+
| id | id2 |
+--------+-------------+
| 123456 | 234233.5156 |
+--------+-------------+
1 row in set (0.00 sec)这样的近似值 ,该怎么解释???
mysql> create table test(id float,id2 float(12,4));
Query OK, 0 rows affected (0.01 sec)mysql> insert into test values(123456.2341,2342334,5234);
ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql> insert into test values(123456.2341,234233.5234);
Query OK, 1 row affected (0.00 sec)mysql> select * from test;
+--------+-------------+
| id | id2 |
+--------+-------------+
| 123456 | 234233.5156 |
+--------+-------------+
1 row in set (0.00 sec)这样的近似值 ,该怎么解释???
需要的时候,再转换成float,
比如0.02元,在数据库中是2
需要的时候,再在程序员把小数点移两位这一方面不需要担心精度问题(一般来说我们都可以明确到要精确到几位)
另一方面也简单(我觉得处理浮点数总是麻烦)