PHP/MySQL: Best money operations/storing practices?

前端 未结 2 460
长情又很酷
长情又很酷 2020-12-28 16:38

So, I am planning to make an application (PHP/MySQL) which deals a lot with money, and I am thinking about how to store and operate with the money, referring to PHP float d

相关标签:
2条回答
  • 2020-12-28 17:08

    I also had trouble finding information about BCMath, so I researched it and wrote my own article about it: http://www.exploringbinary.com/base-conversion-in-php-using-bcmath/ .

    (I'm not taking the stance that you should use BCMath -- I'm just giving you information.)

    0 讨论(0)
  • I'd definitely go for using ints and routing everything through a data object (ORM) style that then handles all conversion for you. The client code using the data object will never need to do conversion and won't care, while you won't have problems with storage as ints are handled easily by the DB. Furthermore, you can then add whatever other methods are needed for the money object (like conversions between money types, etc) quite easily.

    0 讨论(0)
提交回复
热议问题