$money = 271.29;
echo $money =floor ($money *pow (10,2));
This print is 27129
$money = 271.28;
echo $money =floor ($money *pow (10,2));
and the print result is 27127.
Reply to discussion (solution)
$money =271.28;printf ("%.12f", $money *pow (10,2)); 27127.999999999996echo $money =floor ($money *pow (10,2)); 27127
27127.999999999996 is not 27127 after the end of the cut?
$money =271.28;printf ("%.12f", $money *pow (10,2)); 27127.999999999996echo $money =floor ($money *pow (10,2)); 27127
27127.999999999996 is not 27127 after the end of the cut?
Why not 27128.00000000 but 27127.999999999996
Because it is a floating point, there is a natural problem of accuracy.
Please cram your knowledge about floating-point numbers
? in PHP floating??
Can you take a look?? : http://www.laruence.com/2013/03/26/2884.html
http://php.net/manual/zh/function.floor.php
http://php.net/manual/zh/function.ceil.php
http://php.net/manual/zh/function.round.php