https://dev.mysql.com/doc/refman/8.0/en/fixed-point-types.html

This section discusses the characteristics of the DECIMAL data type (and its synonyms), with particular regard to the following topics:

  • Maximum number of digits

  • Storage format

  • Storage requirements

  • The nonstandard MySQL extension to the upper range of DECIMAL columns

The declaration syntax for a DECIMAL column is DECIMAL(M,D). The ranges of values for the arguments are as follows:

  • M is the maximum number of digits (the precision). It has a range of 1 to 65.

  • D is the number of digits to the right of the decimal point (the scale). It has a range of 0 to 30 and must be no larger than M.

If D is omitted, the default is 0. If M is omitted, the default is 10.

The maximum value of 65 for M means that calculations on DECIMAL values are accurate up to 65 digits. This limit of 65 digits of precision also applies to exact-value numeric literals, so the maximum range of such literals differs from before. (There is also a limit on how long the text of DECIMAL literals can be; see Section 12.24.3, “Expression Handling”.)

Values for DECIMAL columns are stored using a binary format that packs nine decimal digits into 4 bytes. The storage requirements for the integer and fractional parts of each value are determined separately. Each multiple of nine digits requires 4 bytes, and any remaining digits left over require some fraction of 4 bytes. The storage required for remaining digits is given by the following table.

Leftover Digits Number of Bytes
0 0
1–2 1
3–4 2
5–6 3
7–9 4

For example, a DECIMAL(18,9) column has nine digits on either side of the decimal point, so the integer part and the fractional part each require 4 bytes. A DECIMAL(20,6) column has fourteen integer digits and six fractional digits. The integer digits require four bytes for nine of the digits and 3 bytes for the remaining five digits. The six fractional digits require 3 bytes.

DECIMAL columns do not store a leading + character or - character or leading 0 digits. If you insert +0003.1 into a DECIMAL(5,1) column, it is stored as 3.1. For negative numbers, a literal - character is not stored.

DECIMAL columns do not permit values larger than the range implied by the column definition. For example, a DECIMAL(3,0) column supports a range of -999 to 999. A DECIMAL(M,D) column permits up to M - D digits to the left of the decimal point.

The SQL standard requires that the precision of NUMERIC(M,D) be exactly M digits. For DECIMAL(M,D), the standard requires a precision of at least M digits but permits more. In MySQL, DECIMAL(M,D) and NUMERIC(M,D) are the same, and both have a precision of exactly M digits.

For a full explanation of the internal format of DECIMAL values, see the file strings/decimal.c in a MySQL source distribution. The format is explained (with an example) in the decimal2bin() function.

[转帖]12.24.2 DECIMAL Data Type Characteristics的更多相关文章

  1. DECIMAL Data Type

    In MySQL, DECIMAL(M,D) and NUMERIC(M,D) are the same, and both have a precision of exactly M digits. ...

  2. mysql data type <----> java data type (数值)

    https://dev.mysql.com/doc/refman/5.7/en/storage-requirements.html +----------------------------+---- ...

  3. MySql and Oracle Data Type Mappings

    the default settings used by SQL Developer to convert data types from MySQL to Oracle. SQL Developer ...

  4. 【转载】salesforce 零基础开发入门学习(四)多表关联下的SOQL以及表字段Data type详解

    salesforce 零基础开发入门学习(四)多表关联下的SOQL以及表字段Data type详解   建立好的数据表在数据库中查看有很多方式,本人目前采用以下两种方式查看数据表. 1.采用schem ...

  5. salesforce 零基础开发入门学习(四)多表关联下的SOQL以及表字段Data type详解

    建立好的数据表在数据库中查看有很多方式,本人目前采用以下两种方式查看数据表. 1.采用schema Builder查看表结构以及多表之间的关联关系,可以登录后点击setup在左侧搜索框输入schema ...

  6. The conversion of a varchar data type to a datetime data type resulted in an out-of-range value

    刚刚有在程序中,传递一个空值至MS SQL Server数据库,这个值的数据类型为DATETIME执行时,它却发生了如标题提示的异常:The conversion of a varchar data ...

  7. Extended Data Type Properties [AX 2012]

    Extended Data Type Properties [AX 2012] This topic has not yet been rated - Rate this topic Updated: ...

  8. 1月21日 Reference Data Type 数据类型,算法基础说明,二分搜索算法。(课程内容)

    Reference Datat Types 引用参考数据类型 -> 组合数据类型 Array, Hash和程序员自定义的复合资料类型 组合数据的修改: 组合数据类型的变量,不是直接存值,而是存一 ...

  9. C++数据类型(data type)介绍

    在编写程序时,数据类型(data type)定义了使用存储空间的(内存)的方式. 程序员通过定义数据类型(data type),告诉特定存储空间这里要存储的数据类型是什么,以及你即将操作他的方式.(注 ...

  10. How to check sqlsever table data type identity status ?

    Unlike in Oracle, sqlserver has an special data type in order by make identity growth. But what abou ...

随机推荐

  1. python 处理pdf加密文件

    近期有同事需要提取加密的pdf文件,截取其中的信息,并且重构pdf文件.网上没有搜到相关的pdf操作,于是咨询了chatgpt,给出了pypdf2的使用案例.但是时间比较久远了,很多库内的调用接口都已 ...

  2. HDU 4893 线段树延迟标记

    原题链接 题意 初始有一长度为n,全为0的序列 每次我们可以对这个序列进行三种操作: 1.将某个位置的数加上d 2.输出某个区间的和 3.将某个区间内每个数字变为与其最接近的斐波那契数,如果有两个最相 ...

  3. 数仓专家面对面 | 为什么我选择GaussDB(DWS)

    摘要:你知道数仓是如何应运而生的吗?你了解数仓未来的发展趋势吗?想知道国内数仓专家的看法吗? 导语 数据仓库的发展一直是备受关注的议题,随着近年来技术的不断演进,数仓也在更新迭代. 你知道数仓是如何应 ...

  4. 一文详述DMS资源池队列阻塞告警及原理

    摘要: 本文主要对DMS资源池队列阻塞告警进行介绍,以及对其背后涉及的内核原理进行介绍. 本文分享自华为云社区<DMS资源池队列阻塞告警及原理介绍>,作者: codefulture. 一. ...

  5. iOS移动应用安全加固:保护您的App免受恶意攻击的重要步骤

    ​ 目录 iOS移动应用安全加固:保护您的App免受恶意攻击的重要步骤 摘要 引言 一.APP加固的概念 二.APP加固方案的比较 三.保护iOS应用的安全 四.总结 参考资料 摘要 本文介绍了移动应 ...

  6. Unsatisfied dependency expressed through field 'restTemplate';

    Test 报错时,添加@注释 解决方案: @SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT)错误如下: ...

  7. 将MyBatis Mapper xml 放到 jar 包外面

    在不改程序的情况下,修改 sql 时,需要将 Mapper 中的 XML 文件 放到外面 mybatis:    mapper-locations: classpath:mapper/*.xml #J ...

  8. Skywalking 8.1 Docker 服务端部署

    前置条件 Docker 安装 Elasticsearch ### 部署服务端 skywalking-oap-server docker pull apache/skywalking-oap-serve ...

  9. 【GO】Go语言介绍 Go开发环境搭建 第一个helloworld 变量命名规范 变量的定义和使用

    今日内容 1 Go语言介绍 #Go语言介绍 Go 即 Golang,是Google公司2009年11月正式对外公开的一门编程语言 Go是[静态 强类型]语言,是区别于解析型语言的编译型语言 静态:类型 ...

  10. 【每日一题】41. 德玛西亚万岁 (状态压缩DP)

    补题链接:Here 经典状压DP问题 坑点,注意多组输入... const int N = 16, mod = 100000000; int f[N][1 << N]; int a[N]; ...