ID: 42628 Comment by: admin at ifyouwantblood dot de Reported By: jortac2002 at yahoo dot com dot mx Status: Open Bug Type: Scripting Engine problem Operating System: WINDOWS XP PROFESSIONAL PHP Version: 5.2.4 New Comment:
This is the thing with floating numbers, just as the manual states: It is quite usual that simple decimal fractions like 0.1 or 0.7 cannot be converted into their internal binary counterparts without a little loss of precision. The follwing works as you would expect it therefore: <? $tree = 366.22; $one = 1519.36; $two = $one - $tree; $four = $two + $tree; $difer = $one - $four; echo "one " . $one . " equals four " . $four . "<br>"; if ($four == $one) { echo "THEY ARE EQUAL <br>"; } else { echo "THEY ARE NOT EQUAL DIFFERENCE " . $difer . "<br>"; } ?> Previous Comments: ------------------------------------------------------------------------ [2007-09-11 19:44:27] jortac2002 at yahoo dot com dot mx Description: ------------ I have the following code : It is very simple code, and the result is very stange because amounts are the same but result shows "NOT EQUAL" Reproduce code: --------------- <html> <body> <? $one = 1519.36; $two = 1153.14; $tree = 366.22; $four = $two + $tree; $difer = $one - $four; echo "one " . $one . " equals four " . $four . "<br>"; if ($four == $one) { echo "THEY ARE EQUAL <br>"; } else { echo "THEY ARE NOT EQUAL DIFFERENCE " . $difer . "<br>"; } ?> </body> </html> Expected result: ---------------- THEY ARE EQUAL Actual result: -------------- THEY ARE NOT EQUAL DIFFERENCE -2.737367544323E-013 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42628&edit=1