In MySQL, the DECIMAL
data type is used to store exact numeric values with a fixed number of digits, both before and after the decimal point. This makes it particulaly useful for financial or monetary data, where precision and accuracy are critical.
Syntax
DECIMAL(M, D)
-
M
is the maxmum number of total digits (precision). -
D
is the number of digits after the decimal point (scale).
Example:
CREATE TABLE `example` (
`amount` DECIMAL(10, 2)
);
This allows up to 10 digits total, with 2 digits after the decimal point (e.g., 12345678.90
).
Top comments (0)