Edit report at https://bugs.php.net/bug.php?id=63960&edit=1
ID: 63960 Updated by: [email protected] Reported by: joern at hv23 dot net Summary: Unexpected result of int() conversion -Status: Open +Status: Not a bug Type: Bug Package: Variables related Operating System: Mac OSX + Linux PHP Version: 5.4.10 Block user comment: N Private report: N 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://www.floating-point-gui.de/ Thank you for your interest in PHP. . Previous Comments: ------------------------------------------------------------------------ [2013-01-10 13:23:41] joern at hv23 dot net Description: ------------ Putting an (int) in front of brackets creates a wrong result - or at least an unexpected result. Output of below script is actually: input = 0.58, output = 57 test3 = 58 test4 = 57 ("0.58"*100) creates a correct 58 (int) ("0.58"*100) gives an incorrect 57 The same happens with input of "0.29", where the output = is 28. It happens on intel as well as AMD cpus. Test script: --------------- $test = "0.58"; $test2 = (int) ($test*100); $test3 = ($test*100); $test4 = (int) ($test*100); echo "input = $test, output = $test2\n"; echo "test3 = $test3\n"; echo "test4 = $test4\n"; Expected result: ---------------- I would expect the output to be: input = 0.58, output = 57 test3 = 58 test4 = 58 Actual result: -------------- Current output: input = 0.58, output = 57 test3 = 58 test4 = 57 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=63960&edit=1
