[转帖]12.24.2 DECIMAL Data Type Characteristics

decimal,data,type,characteristics · 浏览次数 : 0

小编点评

**DECIMAL Data Type** The  DECIMAL  data type is a fixed-point data type that stores numeric values with a specified number of digits and precision. **Key Characteristics:** * **Maximum number of digits:** The maximum number of digits allowed for the precision and scale parts is determined by the arguments passed to the `DECIMAL()` function. * **Storage format:** Values are stored in a binary format that packs nine decimal digits into 4 bytes. * **Scale:** The number of digits to the right of the decimal point (scale) is specified by the `D` argument, with a range of 0 to 30. * **Precision:** The number of digits to the left of the decimal point (precision) is specified by the `M` argument, with a range of 1 to 65. * **Values:** * Integer part: 4 bytes for up to 9 digits * Fractional part: 3 bytes for up to 6 digits **Declaration Syntax:** ```sql DECIMAL(M,D) ``` **Examples:** *  DECIMAL(18,9) : 18 digits in the integer part and 9 digits in the fractional part. *  DECIMAL(20,6) : 20 integer digits and 6 fractional digits. **Note:** * The maximum value of 65 for the `M` argument means calculations on decimal values are accurate up to 65 digits. * Leading and trailing zeros are not stored. *  DECIMAL columns do not support leading or trailing + or - signs or leading 0s.

正文

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 DigitsNumber 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相似的内容:

[转帖]12.24.2 DECIMAL Data Type Characteristics

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),

[转帖]linux系统主机双网卡实现路由转发问题与解决

1. 环境 拓扑: host2 host3"> 网卡配置: host1: 192.168.1.1/24host2: 左eth0: 192.168.1.2/24 右eth1: 192.168.2.2/24 host3: 192.168.2.1/24 2. 需求描述 需要实现主机host1能够与host

[转帖]12.计算机网络---iptables防火墙管理工具

文章目录 一.防火墙基础知识1.1 防火墙是什么?1.2 iptables基础知识1.3 netfilter和iptables的关系:1.4 新型防火墙工具:firewalld 二.iptables的四表五链2.1 规则表2.2 规则链2.3 规则表和规则链之间的关系2.4 数据报的过滤匹配流程:2

[转帖]使用ip命令配置静态ip及网关

一、使用ip命令配置静态IP地址 1.1.1停止网络接口 [rootakojihub~]# ip link set enp2s0 down 1.1.2配置静态IP地址 [root@kojihub~]# ip addr add 192.168.1.1/24 dev enp2s0 1.1.3激活网络接口

[转帖]正则表达式及在Jmeter中的应用

目录 1.正则表达式 1.1 什么是正则表达式 1.2 为什么使用正则表达式 2.语法 2.1 普通字符 2.2 限定符 2.3 非打印字符 2.4 特殊字符 2.5 定位符 2.6 修饰符(标记) 2.7 选择 2.8 运算符优先级 3.常用正则表达式及在线工具 4.Jmeter之正则表达式提取器

[转帖]国产服务器CPU架构与行业研究报告(节选一、二)

https://zhuanlan.zhihu.com/p/504539628 ​ 目录 收起 1 服务器与CPU技术综述 1.1 服务器综述 1.2 CPU综述 2 服务器CPU架构概况 2.1 服务器CPU的架构分类 2.2 CISC-x86 2.3 RISC- ARM 2.4 RISC-V 2.

[转帖]jvm学习三-MAT内存分析工具的使用

目录 1 模拟内存溢出程序 1.1 jvm配置 1.2 测试代码 2 MAT工具进行内存分析 2.1 大纲介绍 2.2 Histogram视图介绍 2.3 Leak Suspects视图介绍 2.4 Dominator Tree 1 模拟内存溢出程序 1.1 jvm配置 -XX:+PrintGCDe

[转帖]Redis进阶(发布订阅,PipeLine,持久化,内存淘汰)

目录 1、发布订阅 1.1 什么是发布订阅 1.2 客户端实例演示 1.3 Java API演示 1.4 Redis发布订阅和rabbitmq的区别 2、批量操作 2.1 普通模式与 PipeLine 模式 2.2 适用场景 2.3 源码解析 2.4 Pipelining的局限性 2.5 事务与 L

[转帖]docker 最新版本升级

文章目录 前言一、卸载低版本docker1.1 检查docker版本1.2 删除docker 二、开始安装2.1 安装所需依赖2.2 设置docker yum源2.3 查看所有可用版本2.4 安装Docker 三、启动Docker3.1 启动docker服务、设置开机自启3.2 重启机器测试3.3

[转帖]centos7 firewall-cmd主机之间端口转发

目录 1. firewalld1.1 firewalld守护进程1.2 控制端口/服务1.3 伪装IP1.4 端口转发 2. 案例2.1 配置ServerA2.2 安装nginx测试 (可选)2.3 开启端口2.4 伪装IP2.5 端口转发2.6 配置ServerB2.7 修改nginx页面显示内容