MySQL :: MySQL 8.4 Reference Manual :: 13.1.3 Fixed-Point Types (Exact Value) (original) (raw)
13.1.3 Fixed-Point Types (Exact Value) - DECIMAL, NUMERIC
The DECIMAL
and NUMERIC
types store exact numeric data values. These types are used when it is important to preserve exact precision, for example with monetary data. In MySQL, NUMERIC
is implemented as DECIMAL
, so the following remarks about DECIMAL
apply equally toNUMERIC
.
MySQL stores DECIMAL
values in binary format. See Section 14.24, “Precision Math”.
In a DECIMAL
column declaration, the precision and scale can be (and usually is) specified. For example:
salary DECIMAL(5,2)
In this example, 5
is the precision and2
is the scale. The precision represents the number of significant digits that are stored for values, and the scale represents the number of digits that can be stored following the decimal point.
Standard SQL requires that DECIMAL(5,2)
be able to store any value with five digits and two decimals, so values that can be stored in the salary
column range from -999.99
to999.99
.
In standard SQL, the syntaxDECIMAL(_`M`_)
is equivalent toDECIMAL(_`M`_,0)
. Similarly, the syntax DECIMAL
is equivalent to DECIMAL(_`M`_,0)
, where the implementation is permitted to decide the value of_M
_. MySQL supports both of these variant forms of DECIMAL
syntax. The default value of M
is 10.
If the scale is 0, DECIMAL
values contain no decimal point or fractional part.
The maximum number of digits for DECIMAL
is 65, but the actual range for a given DECIMAL
column can be constrained by the precision or scale for a given column. When such a column is assigned a value with more digits following the decimal point than are permitted by the specified scale, the value is converted to that scale. (The precise behavior is operating system-specific, but generally the effect is truncation to the permissible number of digits.)