Should I store a field PRICE as an int or as a float int the database?

后端 未结 4 835
小蘑菇
小蘑菇 2021-02-20 03:21

In a previous project, I noticed that the price field was being stored as an int, rather than as a float. This is done by multiplying the actual value by 100, the reason being

4条回答
  •  佛祖请我去吃肉
    2021-02-20 03:55

    Floating point errors could cause you problems if you are multiplying large numbers. In general, financial calculations should never be done with floating point numbers where possible.

提交回复
热议问题