看了一些博客,觉得很多都是复制的,不如自己亲测一篇:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41create table decimal_test( id int auto_increment PRIMARY key, score decimal(5,2) -- 取值范围是 -999.99 到 999.99 ); -- 整数的位数必须小于等于m-d,不然报错。小数的位数可以大于d位。多出d位时会做四舍五入,截取到d位。 -- 以上均不包括小数点、符号的位数。数字的总长度是m位,保存后的小数位最多是d位。如果保存后是整数,小数位不会补0。 -- 以下测试版本是5.7.14 select * from decimal_test; -- 正数: insert into decimal_test(score) VALUES(1.23); -- 1.23 insert into decimal_test(score) VALUES(123.45); -- 123.45 insert into decimal_test(score) VALUES(123.455); -- 123.46 insert into decimal_test(score) VALUES(123.451); -- 123.45 insert into decimal_test(score) VALUES(123.451123); -- 123.45 insert into decimal_test(score) VALUES(12345.451123); -- Out of range value for column 'score' insert into decimal_test(score) VALUES(9999.451123); -- Out of range value for column 'score' insert into decimal_test(score) VALUES(999.451123234324); -- 999.45 insert into decimal_test(score) VALUES(999.999999999); -- Out of range value for column 'score' insert into decimal_test(score) VALUES(999.99123); -- 999.99 -- 负数: insert into decimal_test(score) VALUES(-1.23); -- -1.23 insert into decimal_test(score) VALUES(-12.34); -- -12.34 insert into decimal_test(score) VALUES(-123.45); -- -123.45 insert into decimal_test(score) VALUES(-999.45); -- -999.45 insert into decimal_test(score) VALUES(-12343); -- Out of range value for column 'score' insert into decimal_test(score) VALUES(12343); -- Out of range value for column 'score' insert into decimal_test(score) VALUES(1234); -- Out of range value for column 'score' insert into decimal_test(score) VALUES(123); -- 123 insert into decimal_test(score) VALUES(-123); -- -123 insert into decimal_test(score) VALUES(-999.99); -- -999.99 insert into decimal_test(score) VALUES(-9990.99); -- Out of range value for column 'score' insert into decimal_test(score) VALUES(-1234.99); -- Out of range value for column 'score' insert into decimal_test(score) VALUES(-1234); -- Out of range value for column 'score' select VERSION() ; -- 5.7.14
最后
以上就是满意蜗牛最近收集整理的关于Mysql decimal(m,d)的说明的全部内容,更多相关Mysql内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复