zoukankan      html  css  js  c++  java
  • MySQL(六) decimal数据默认处理

    create table decimal_test(
    id int auto_increment PRIMARY key,
    score decimal(5,2) -- 取值范围是 -999.99 到 999.99
    );

    decimal(M,D)M=整数位+小数位
    -- 整数的位数必须小于等于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.6.30

  • 相关阅读:
    [PKUSC2018]星际穿越——可持久化线段树+DP
    BZOJ2863[SHOI2012]魔法树——树链剖分+线段树
    BZOJ1758[Wc2010]重建计划——分数规划+长链剖分+线段树+二分答案+树形DP
    BZOJ4543[POI2014]Hotel加强版——长链剖分+树形DP
    树链剖分讲解及总结(重链剖分+长链剖分)
    Dubbo(3)--dubbo的源码分析
    Dubbo(1)--初识Dubbo
    zookeeper(5)--基于watcher原理实现带注册中心的RPC框架
    模板方法模式
    单例模式
  • 原文地址:https://www.cnblogs.com/fanBlog/p/11321580.html
Copyright © 2011-2022 走看看