MySQL DECIMAL Length: Setting Precision & Scale
The DECIMAL data type in MySQL is used for storing precise decimal values. When creating a column with the DECIMAL type, you can specify two parameters: precision and scale.
Precision refers to the maximum number of digits, including both integer and decimal places, that a column can store. Scale specifies the number of digits after the decimal point.
For example, if you create a column with the data type DECIMAL(5,2), it can store numbers with a maximum of 5 digits, including decimal places. With 2 decimal places, the maximum number it can store is 999.99.
Here are some examples:
- DECIMAL(5,2): The maximum number that can be stored is 999.99.
- Decimal(10,3): The largest number it can store is 9999.999.
- DECIMAL(8,0): The maximum number that can be stored is 99999999.
It should be noted that the range of precision and decimal places is between 1 and 65. The number of decimal places cannot exceed the precision.