ID: 48846 Updated by: [email protected] Reported By: marcin at datamomentu dot eu -Status: Open +Status: Bogus Bug Type: Variables related Operating System: Windows XP PHP Version: 5.3.0 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: ------------------------------------------------------------------------ [2009-07-08 06:52:00] marcin at datamomentu dot eu Description: ------------ $t1 = floatval(8.95); var_dump($t1); $t2 = $t1*100; var_dump($t2); $t3 = (int)$t2; var_dump($t3); t3 should be 8.95 and its 8.94 its true for t1 = 7.95 or 9.95 its not true for t1 = 6.95 or 5.95 or 4.95 etc Reproduce code: --------------- $t1 = floatval(8.95); var_dump($t1); t2 = $t1*100; var_dump($t2); $t3 = (int)$t2; var_dump($t3); Expected result: ---------------- t3 = 8.95 Actual result: -------------- t3 = 8.94 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=48846&edit=1
