Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What MySQL type is most suitable for "price" column?

Tags:

mysql

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.

like image 369
Misha Moroshko Avatar asked Dec 09 '10 10:12

Misha Moroshko


People also ask

What is the best data type for money in MySQL?

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.

What is data type for money?

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).

What is the best data type for salary in SQL?

Numeric data types are normally used to store data like price, salary etc.


1 Answers

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

like image 106
beastofman Avatar answered Sep 24 '22 15:09

beastofman