PHP Adding 2 decimal points numbers (money) gives wrong results in total amount

后端 未结 7 584
傲寒
傲寒 2021-01-13 00:30

I have an customer invoice table in my MySQL database with a DECIMAL(10,2) field called price.

When fetching these values in php and calculating a sum amount,

7条回答
  •  没有蜡笔的小新
    2021-01-13 01:10

    If you need accuracy of 2 decimal points:

    1. multiply value by 100
    2. do your operations
    3. divide by 100 and use number_format where appropriate

提交回复
热议问题