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

后端 未结 7 586
傲寒
傲寒 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:09

    Indeed, floating point numbers are not precise.
    Either calculate in cent (multiply by 100 and calculate in integers), or calculate in strings using BC Math.

提交回复
热议问题