take the following:
Code: Select all
$number = 227*0.175;
echo "number = $number<BR>";
echo "cast to float : ".(float) $number."<BR>";
echo "var_dump : ".var_dump($number)."<BR>";
echo "using round : ". round($number,2)."<BR>";
echo "using number format : ". number_format($number,2,".","")."<BR>";
echo "multiply by 100 and round to int: ".round($number*100)."<BR>";
echo "multiply by 100 and cast to int : ".(int)($number*100)."<BR>";Code: Select all
number = 39.725
cast to float : 39.725
float(39.725) var_dump :
using round : 39.72
using number format : 39.72
multiply by 100 and round to int: 3972
multiply by 100 and cast to int : 3972If I say $number = 39.725 then it rounds upwards to 39.73 (except for casting to int).
How do I get around this?
I'm trying to make sure all the figures work out as they do in our acconting software. They probably store pence rather than pounds but I'm not sure this would make any difference in this case. If I multiply by a float (0.175) then I'll end up with a float again, won't I.
HELP ME!!!