mysql decimal(6_MySQL(六) decimal数据默认处理
create table decimal_test(
id int auto_increment PRIMARY key,
score decimal(5,2) -- 取值范圍是 -999.99 到 999.99
);
decimal(M,D)M=整數(shù)位+小數(shù)位
-- 整數(shù)的位數(shù)必須小于等于m-d,不然報(bào)錯(cuò)。小數(shù)的位數(shù)可以大于d位。多出d位時(shí)會做四舍五入,截取到d位。
-- 以上均不包括小數(shù)點(diǎn)、符號的位數(shù)。數(shù)字的總長度是m位,保存后的小數(shù)位最多是d位。如果保存后是整數(shù),小數(shù)位不會補(bǔ)0。
-- 以下測試版本是5.7.14
select * from decimal_test;
-- 正數(shù):
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
-- 負(fù)數(shù):
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.6.30
總結(jié)
以上是生活随笔為你收集整理的mysql decimal(6_MySQL(六) decimal数据默认处理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php把amr转换成mp3,amr怎么转
- 下一篇: mysql 热备 windows_win