Edit report at http://bugs.php.net/bug.php?id=52188&edit=1
ID: 52188 Updated by: ras...@php.net Reported by: hostmaster at ovi dot com Summary: Arithmetic Operator: Addition maybe have a problem -Status: Open +Status: Bogus Type: Feature/Change Request Package: Scripting Engine problem Operating System: openSuSE PHP Version: 5.3.2 New Comment: Floating point values have a limited precision. Hence a value might not have the same string representation after any processing. That also includes writing a floating point value in your script and directly printing it without any mathematical operations. If you would like to know more about "floats" and what IEEE 754 is, read this: http://docs.sun.com/source/806-3568/ncg_goldberg.html Thank you for your interest in PHP. . Previous Comments: ------------------------------------------------------------------------ [2010-06-26 01:05:26] hostmaster at ovi dot com Description: ------------ PHP version: 5.3.2 I think addition operator have a problem. Pls run the script below and the code in "Test script" box. <?php $a = 16.99; $b = 6.99; $c = 10; if ($a < ($b + $c)) { print "<"; } else if ($a == ($b + $c)) { print "=="; } else { print ">"; } print "\n"; print $a .":". ($b + $c); print "\n"; ?> If the number is 16.98, the result will be ok. Test script: --------------- <?php for ($x=0;$x<100;$x++ ) { for ($y=10;$y<100;$y++) { $str = $x.'.'.$y; print $str; $a = floatVal($str); $b = floatVal($x); $c = floatVal('0.'.$y); if ($a < ($b + $c)) { print "<"; } else if ($a == ($b + $c)) { print "=="; } else { print ">"; } print "\n"; } } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=52188&edit=1