Exact numerical type-Decimal type
Decimal data type is used to store exact numeric values. Accurate numerical types are used in scenarios where very accurate numerical accuracy is required, such as bank account numbers, or rigorous scientific calculations. In Decimal's column name declaration, integer and decimal parts are generally declared. For example, the following example:
Salary DECIMAL(5,2)
In this case, 5 is the number of significant digits and 2 is the decimal digits. Integer accuracy represents the number of significant digits stored in the numerical part, and decimal precision represents the number of significant digits stored in the decimal part. Standard SQL requires DECIMAL(5,2) to store 5 digits and 2 decimals, so if the salary column digits represented in this form should range from -999.99 to 999.99. In MatrixOne's syntax, DECIMAL(M) and DECIMAL(M,0) are the same. If DECIMAL is declared directly, the syntax will also be parsed into DECIMAL(M,0), and the default value of M is 10. If the decimal accuracy is 0, DECIMAL is equivalent to a pure integer and does not contain any decimals. The maximum number of digits of the DECIMAL type in MatrixOne is 38 bits. In addition, the integer or decimal number specified in DECIMAL exceeds the specified range when the actual column is assigned, and the actual value will be automatically converted to the corresponding accuracy.
Decimal Data Type Features
This part mainly introduces some characteristics of Decimal data types, especially in bit precision and storage form.
The declaration syntax of the DECIMAL column is DECIMAL(M, D), M is the number of digits of a significant number, the value range is 1 to 38, D is the number of decimal places, the value range is 1 to 38, but it cannot be greater than M. If D is not specified, the default is 0. If M is not specified, the default is 10.
The values of the DECIMAL column are stored in binary form. Inside MatrixOne, there are only two representations: decimal64 and decimal128. Within 0-18 bit accuracy, a Decimal value occupies 8 bytes of storage space, and within 19-38 bit accuracy, a Decimal value occupies 16 bytes of storage space.
| digits | bytes |
|---|---|
| 0-18 | 8 bytes |
| 19-38 | 16 bytes |