MySQL: preferred column type for (product) prices?

前端 未结 5 2000
你的背包
你的背包 2021-01-30 19:34

In MySQL, what is the preferred column type for storing a product\'s price (or currencies in general)? Google learned me DECIMAL of FLOAT is often used, but I wonder which one i

5条回答
  •  不知归路
    2021-01-30 20:17

    Field type "Decimal" is good.

    If you have highe prices then you can use product_price decimal(6,2) NOT NULL, i.e. you can store prices up to 6 digits with decimal point before 2 digits.

    Maximum value for field product_price decimal(6,2) NOT NULL, will store price up to 9999.99

    If all prices are between 0.01 to 25.00 then product_price decimal(4,2) NOT NULL, will be good, but if you will have higher prices then you can set any values in decimal(4,2).

提交回复
热议问题