Hi, can someone explain to me whats wrong with this script. Looking at the code it all seems pretty simple, but what php outputs is really unexpected:
header('content-type: text/plain');
$d = 2;
for($i = 0.01; $i <= 10; $i += 0.01)
{
$a = $i;
$a = $a / 1.175;
$a = round($a, $d);
$a = $a * 1.175;
$a = round($a, 2);
$r = ($i == $a) ? 'ok' : 'error';
echo $i."\t".$a."\t".$r."\n";
}
As you should be able to see, every number after 0.16 says error, even though you can quite clearly see that the two numbers do match, and then once $i gets to
4.43 it completly screws up.
Im sure there is no error in the script and there is nothing that tells the value of $i to be any more than two decimals long.
Im running PHP 4.4.2. Here is some sample output:
4.36 4.36 error
4.37 4.37 error
4.38 4.38 error
4.39 4.39 error
4.4 4.39 error
4.41 4.41 error
4.42 4.42 error
4.43 4.43 error
4.4399999999999 4.44 error
4.4499999999999 4.45 error
4.4599999999999 4.47 error
4.4699999999999 4.47 error
4.4799999999999 4.48 error
4.4899999999999 4.49 error
4.4999999999999 4.5 error
4.5099999999999 4.51 error
Thanks in advance.
Jack