Can anyone explain this code's output?
<?php
$x = (15/100) * 10.7;
$y = 1.605;
var_dump($x, $y, round($x,2), round($y,2),round(1.605,2));
?>
Result:
float(1.605) float(1.605) float(1.6) float(1.61) float(1.61)
In other words there is a difference between the values of $x and $y
where they should both be 1.605 (and var_dump shows them both to be 1.605).
I assume this is because $x isn't really 1.605, but something very close
to (and slightly below) 1.605 due to a rounding issue, so rounding to 2
decimal places causes it to round down not up. But I'm not sure how to
change the code to give the correct results?
(15/100 you may notice as VAT; this is a VAT calculation, therefore I'm
kinda duty bound to get the right result!)
--
Mark Rogers // More Solutions Ltd (Peterborough Office) // 0844 251 1450C
Registered in England (0456 0902) @ 13 Clarke Rd, Milton Keynes, MK1 1LG