Documentation Home
MySQL 9.4 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 41.2Mb
PDF (A4) - 41.3Mb
Man Pages (TGZ) - 262.8Kb
Man Pages (Zip) - 368.8Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb


MySQL 9.4 Reference Manual  / ...  / Data Types  / Numeric Data Types  /  Fixed-Point Types (Exact Value) - DECIMAL, NUMERIC

13.1.3 Fixed-Point Types (Exact Value) - DECIMAL, NUMERIC

TheDECIMAL andNUMERIC 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 asDECIMAL, so the following remarks aboutDECIMAL apply equally toNUMERIC.

MySQL storesDECIMAL values in binary format. SeeSection 14.25, “Precision Math”.

In aDECIMAL 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 thatDECIMAL(5,2) be able to store any value with five digits and two decimals, so values that can be stored in thesalary column range from-999.99 to999.99.

In standard SQL, the syntaxDECIMAL(M) is equivalent toDECIMAL(M,0). Similarly, the syntaxDECIMAL is equivalent toDECIMAL(M,0), where the implementation is permitted to decide the value ofM. MySQL supports both of these variant forms ofDECIMAL syntax. The default value ofM is 10.

If the scale is 0,DECIMAL values contain no decimal point or fractional part.

The maximum number of digits forDECIMAL is 65, but the actual range for a givenDECIMAL 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.)