MySQL's DECIMAL
and NUMERIC
types store exact numeric data values. It is recommended to use these types to preserve exact precision, such as for money.
These values are stored in binary format. In a column declaration, the precision and scale should be specified
Precision represents the number of significant digits that are stored for values.
Scale represents the number of digits stored after the decimal
salary DECIMAL(5,2)
5 represents the precision
and 2 represents the scale
. For this example, the range of values that can be stored in this column is -999.99 to 999.99
If the scale parameter is omitted, it defaults to 0
This data type can store up to 65 digits.
The number of bytes taken by DECIMAL(M,N)
is approximately M/2
.