What type of MySQL is most suitable for the price column?

I have a price column in the products table.

I wonder what type of MySQL is 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, as in stores).

Please inform.

+42
mysql
Dec 09 '10 at
source share
4 answers

DECIMAL decimal values ​​are stored exactly. For example. DECIMAL (10, 2) is ideal for prices not higher than 99999999.99. MySQL Docs Reference

+74
Dec 09 '10 at 10:52
source share

DECIMAL is the best choice. You will need to specify the accuracy and scale for the column. Precision indicates the total number of digits that the number will contain, and scale indicates how many of them are intended to be used in the exponent.

+10
Dec 09 '10 at 10:49
source share

The Decimal field type will work best. How:

 `product_price` decimal(8, 2) NOT NULL, 

It will save the price until 999999.99

If you have high prices, you can use

 `product_price` decimal(12, 2) NOT NULL, 

i.e. up to 9999999999.99

+10
Feb 14 '13 at 7:31
source share

You must definitely use the decimal type for money. Never a floating point, contrary to other answers. And using varchar prevents the execution of calculations.

+5
Dec 09 '10 at 10:48
source share



All Articles