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

后端 未结 4 828
小蘑菇
小蘑菇 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 04:01

    While it would save you float-related issues, having prices saved as integers might lead to a problem where you end up charging 100 times the price to a customer. It could also confuse other programmers.

    I have seen both solution used successfully on medium-size ecommerce websites, but my preference goes to using floats.

提交回复
热议问题