ID: 36730 Updated by: [EMAIL PROTECTED] Reported By: scott dot fagg at arup dot com -Status: Open +Status: Bogus Bug Type: *Math Functions Operating System: linux PHP Version: 4.4.2 New Comment:
This is not a bug. Please read the short note at http://php.net/float Previous Comments: ------------------------------------------------------------------------ [2006-03-14 01:20:46] scott dot fagg at arup dot com Description: ------------ (int) and intval() generate wrong values. Output of (int) and intval() is affected by how the values passed to them, were calculated. Reproduce code: --------------- $x = 0.57 ; $a = (int) ($x * 100); $b = intval($x * 100); # produce incorrect results , $b = 56 print "$x $a $b\n"; $x = 0.56 + 0.01; $a = (int) ($x * 100); $b = intval($x * 100); # produce expected results , $b = 57 print "$x $a $b\n"; Expected result: ---------------- (int) and intval() should produce correct answers and should not be affected by how the values passed to them are calculated. Workaround seems to be to use round() instead of intval(). Actual result: -------------- Above code produces : 0.57 56 56 0.57 57 57 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=36730&edit=1