ID: 40622 Updated by: [EMAIL PROTECTED] Reported By: bruno dot boccara at d2b dot com -Status: Open +Status: Bogus Bug Type: Math related Operating System: windows 2003 Apache 2 PHP Version: 4.4.5 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: ------------------------------------------------------------------------ [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
