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

后端 未结 7 540
傲寒
傲寒 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:19

    You could use number_format

    Ex:(for two decimal points)

    $number = 12345.5667;
    echo $result = number_format($number, 2);
    

    Or you could use round function in MySql:

    ROUND(number,2)
    
    0 讨论(0)
提交回复
热议问题