On 12 Oct 11:08, Mark Rogers wrote:
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).
Can I make a simple suggestion...
Rather than doing the maths in the order that you have in $x do: $x = 10.7 * 15 * 0.01;
I.e. you're doing the division at the end, rather than the beginning, and so the float is "more accurate".
Hope that helps,