我在MySQL中有一个表,其中包含十进制,长度为9,无符号的字段.我用它来代价.
在我插入数据并查询它之后,它全部被舍入并且小数已被删除.
我很困惑为什么.
疑难解答?
主持人:web.com
phpMyAdmin版本:2.11.10.1
MySQL客户端版本:5.0.95
Ser*_*sev 16
MySQL中的十进制类型有两个调整旋钮:精度和比例.您省略了比例,因此默认为0.
DECIMAL列的声明语法是DECIMAL(M,D).MySQL 5.1中参数的值范围如下:
M是最大位数(精度).它的范围是1到65.(旧版本的MySQL允许范围为1到254).
D是小数点右边的位数(刻度).它的范围为0到30,且不得大于M.
mysql> create table test01 (field01 decimal(9));
Query OK, 0 rows affected (0.01 sec)
mysql> insert into test01 (field01) values (123.456);
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> select * from test01;
+---------+
| field01 |
+---------+
| 123 |
+---------+
1 row in set (0.00 sec)
mysql> create table test02 (field01 decimal(9, 4));
Query OK, 0 rows affected (0.00 sec)
mysql> insert into test02 (field01) values (123.456);
Query OK, 1 row affected (0.01 sec)
mysql> select * from test02;
+----------+
| field01 |
+----------+
| 123.4560 |
+----------+
1 row in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)