I have a price
column in products
table.
I wonder which MySQL type is the most suitable for this column. Is it DECIMAL
, FLOAT
, or something else ?
The price can be for example: 139.99
, 40
, 14.5
(2 digits after the decimal point, like in shops).
Please advise.
We can store the money values in MySQL in decimal(value1,value2). Here, value1 is the total range including value2. The value2 specifies the number of digits after the decimal point.
Unlike the DECIMAL data type, the MONEY data type is always treated as a fixed-point decimal number. The database server defines the data type MONEY(p) as DECIMAL(p,2). If the precision and scale are not specified, the database server defines a MONEY column as DECIMAL(16,2).
Numeric data types are normally used to store data like price, salary etc.
DECIMAL beacuse decimal value is stored precisely. E.g. DECIMAL(10, 2) will suit perfectly for prices not higher than 99999999,99. MySQL Docs reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With