ID: 17282 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] -Status: Open +Status: Bogus Bug Type: Scripting Engine problem Operating System: FreeBSD 4.4-STABLE PHP Version: 4.2.1 New Comment:
You can't compare floats like this, a float is an approximation of the number, but never exact the number. This is not a bug, this wouldn't work in most languages, including C -> Bogus Previous Comments: ------------------------------------------------------------------------ [2002-05-16 22:23:02] [EMAIL PROTECTED] This problem also occurs on PHP 4.1.2. The following code fragment produces very odd results: <? $a = array(41.96, 20.97, 20.99); $t = 0; for($i = 1; $i < count($a); $i++) $t += abs($a[$i]); echo "$t != $a[0]\n"; var_dump($t != $a[0]); echo "t = "; var_dump($t); echo "a[0] = "; var_dump($a[0]); ?> The results are shown below: 41.96 != 41.96 bool(true) t = float(41.96) a[0] = float(41.96) Both variables appear to be the same type, and look the same, yet compare incorrectly with both typed and untyped comparisons. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=17282&edit=1