ID: 40622 User updated by: bruno dot boccara at d2b dot com Reported By: bruno dot boccara at d2b dot com Status: Bogus Bug Type: Math related Operating System: windows 2003 Apache 2 PHP Version: 4.4.5 New Comment:
Did I send an email to a robot ?? Each user who ask this question get the same answer. You should be ashaimed to do this. You know that this is a a very big bug of PHP and no one is ready to resolve it ! This is not a way to do. I'm very very desappointed. For other users with this problem, you can do like me in the example to avoid this problem. This will slow down a little the result. Use the settype function to convert the number to string and then to float. I did'n test it in all cases, but it seems to work. Previous Comments: ------------------------------------------------------------------------ [2007-02-24 22:05:52] [EMAIL PROTECTED] 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. . ------------------------------------------------------------------------ [2007-02-24 21:36:47] bruno dot boccara at d2b dot com Description: ------------ round function gives wrong value. Please do not send me to http://docs.sun.com/source/806-3568/ncg_goldberg.html, you have to admit that this is a bug !!!!! if not, php CANNOT be use in production site with mathematical functions !!! Reproduce code: --------------- <? // 140.25*(1-(34/100)) = 92.565 echo "formula = ". round(((140.25*(1-(34/100)))),2);echo "<br>"; echo "direct = ".round (92.565, 2);echo "<br>"; $valeur = 140.25*(1-(34/100)); echo "value = ".round($valeur,2);echo "<br>"; settype($valeur,"string"); settype($valeur,"float"); echo "value2 = ".round($valeur,2); ?> Expected result: ---------------- formula = 92.57 direct = 92.57 value = 92.57 value2 = 92.57 Actual result: -------------- formula = 92.56 // WRONG ! direct = 92.57 value = 92.56 // WRONG ! value2 = 92.57 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=40622&edit=1