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

后端 未结 7 539
傲寒
傲寒 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:14

    Well, to begin with, why sum in a php loop when you can do that in mysql? Moreover, just use integer multiplied by 100 and then divide by 100 once you need the final result.

提交回复
热议问题