MySQL: preferred column type for (product) prices?

前端 未结 5 1914
你的背包
你的背包 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:00

    I would not use float as that can give rounding errors, as it is a floating point type.

    Use decimal:

    "The DECIMAL and NUMERIC types are used to store values for which it is important to preserve exact precision, for example with monetary data."

    see: http://dev.mysql.com/doc/mysql/en/numeric-types.html

提交回复
热议问题