Misha Moroshko
Misha Moroshko

Reputation: 171399

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

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.

Upvotes: 66

Views: 91549

Answers (3)

beastofman
beastofman

Reputation: 1361

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

Upvotes: 101

Ali Nawaz
Ali Nawaz

Reputation: 1016

Field type "Decimal" will work best. Like:

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

It will store a price up to 999999.99

If you have high prices then you can use

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

i.e. up to 9999999999.99

Upvotes: 18

user207421
user207421

Reputation: 311008

You should certainly use a decimal type for money. Never floating point, contrary to other answers. And using varchar prevents you doing calculations.

Upvotes: 7

Related Questions