MysqL中的小数类型有两个调整旋钮:精度和小数位数。您省略了小数位,因此默认为0。
changes.html))
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)