DECIMAL
The DECIMAL type is used to represent numbers with a specific maximum precision and fixed decimal places. This data type is very useful in scenarios that require precise numerical calculations, such as finance, accounting, or other fields, because it can avoid rounding errors associated with floating-point numbers.
Syntax
precision: Represents the total number of digits, including digits on both sides of the decimal point. The value range is from 1 to 38.scale: Represents the number of digits after the decimal point. The value range is from 0 toprecision, and it cannot be greater thanprecision.
Example
User Guide
- When
scaleis 0, it means the value is an integer. - When the values of
precisionandscaleare the same, it means the value is a pure decimal. - When performing numerical conversions, if the conversion result exceeds the range of the
DECIMALtype, data truncation or rounding may occur. - When comparing
DECIMALtype values, their precision and scale should be considered to avoid comparison errors due to rounding errors.
Notes
- When using the
DECIMALtype, the values ofprecisionandscaleshould be reasonably chosen according to actual needs to ensure the accuracy of the values and calculations.
