ID: 41907 User updated by: milman at gmx dot de Reported By: milman at gmx dot de Status: Bogus Bug Type: *Math Functions Operating System: windows xp PHP Version: 5.2.3 New Comment:
sorry but i can't accept this answer. for me it seem like, round-problem than bogus and standard answer. php use common round (Symmetric Arithmetic Rounding) Decide which is the last digit to keep. Increase it by 1 if the next digit is 5 or more (this is called rounding up) Leave it the same if the next digit is 4 or less (this is called rounding down) and then round (8.155, 2) is 8.16 and not 8.15 sprintf ("%15.8f", 8.155) is 000008.15500000 so it is not a problem from intern representation. the rounding problem occurs at number_format and sprintf too. round Previous Comments: ------------------------------------------------------------------------ [2007-07-05 16:30:05] [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-07-05 16:27:24] milman at gmx dot de Description: ------------ wrong result from round(64.365,2) should be 64.37 not 64.36 Reproduce code: --------------- <? echo "right: round (63.365,2) = " . round (63.365,2) . "<br>\n" ; echo "wrong: round (64.365,2) = " . round (64.365,2) . "<br>\n" ; echo "wrong: round (81.365,2) = " . round (81.365,2) . "<br>\n" ; echo "right: round (82.365,2) = " . round (82.365,2) . "<br>\n" ; ?> Expected result: ---------------- allway .37 not somtimes .36 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=41907&edit=1