Mysql decimal(m,d)的说明

Mysql decimal(m,d)的说明看了一些博客,觉得很多都是复制的,不如自己亲测一篇:createtabledecimal_test(idintauto_incrementPRIMARYkey,scoredecimal(5,2)–取值范围是-999.99到999.99);–整数的位数必须小于等于m-d,不然报错。小数的位数可以大于d位。多…

大家好,又见面了,我是你们的朋友全栈君。

看了一些博客,觉得很多都是复制的,不如自己亲测一篇:                          

create 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 decimal(m,d)的说明 

 

Mysql decimal(m,d)的说明

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/160867.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 小程序面试题及答案2019_小程序面试问的技术点

    小程序面试题及答案2019_小程序面试问的技术点文档描述本文是关注微信小程序的开发和面试问题,由基础到困难循序渐进,适合面试和开发小程序。并有热点框架(vuereactnode.js全栈)前端资源以及后端视频资源和源码并基于前端进阶和面试的需求总结了常用插件和js算法以及html/css和js热点面试题因为csdn不可以有外链所以答案链接在评论区!!!Vue面试题生命周期函数面试题1.什么是…

    2022年8月29日
    5
  • 关于input type=“file”的及其files对象的深层探究

    关于input type=“file”的及其files对象的深层探究我们都知道,html5中有个inputtype=file元素。用该元素可以实现页面上传文件的功能但一般的做法只是简单的在表单中操作,我来研究一下深层东西想要了解它,就要知道它的内置对象,files页面上写一个input,然后选俩个图片,打印这个input对象$(“input[name=’file1′]”).change(function(e){console.log…

    2022年4月30日
    34
  • linux如何查看防火墙是否开启?删除iptables规则

    linux如何查看防火墙是否开启?删除iptables规则

    2021年11月3日
    58
  • python爬取琳琅社区整站视频(一晚6000部)[通俗易懂]

    python爬取琳琅社区整站视频(一晚6000部)[通俗易懂]琳琅社区(传闻中最受男人喜爱的网站),哼哼,我倒要看看是不是真的该项目用于爬取琳琅社区整站视频(仅供学习)主要使用:python3.7+scrapy2.19+Mysql8.0+win10首先确定需要爬取的内容,定义item:classLinglangItem(scrapy.Item): #视频属于哪个模块video_belong_module=scrap…

    2022年6月25日
    25
  • C/C++指针详解之基础篇(史上最全最易懂指针学习指南!!!!)「建议收藏」

    C/C++指针详解之基础篇(史上最全最易懂指针学习指南!!!!)「建议收藏」目录一.变量的内存实质到1.1变量的实质1.2赋值给变量1.3变量在哪里?二.指针是个什么东西?三.二级指针(指针的指针)3.1定义与初始化3.2间接数据访问3.2.1.改变一级指针指向3.2.2改变N-1级指针的指向3.2.3二级指针的步长四.指针与数组4.1指针与数组名4.1.1通过数组名访问数组元素4….

    2022年5月22日
    38
  • Java四舍五入保留两位小数

    Java四舍五入保留两位小数文章目录Java四舍五入保留两位小数一、前言环境二、正文BigDecimalDecimalFormatMathcommons-math3String#formatJava四舍五入保留两位小数一、前言环境开发工具:IntelliJIDEAJDK:1.8BigDecimal:https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.htmlDecimalFormat:https://docs.oracle.com/java

    2022年5月21日
    34

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号