Edit report at http://bugs.php.net/bug.php?id=53972&edit=1
ID: 53972 Updated by: johan...@php.net Reported by: thipse_rahul at rediffmail dot com Summary: Operator Type Casting Issue Status: Bogus Type: Bug Package: *General Issues Operating System: Linux/Windows PHP Version: 5.3.5 Block user comment: N Private report: N New Comment: 0.1+0.9 is not exactly 1 but a tiny bit less. (int) rounds down. Previous Comments: ------------------------------------------------------------------------ [2011-02-10 05:16:35] thipse_rahul at rediffmail dot com Thanks for reply johannes Yes I agree for float, Then Whey Case(2) & Case(3) gives wrong result. Case 2: $a = (int)((0.1+0.6) * 10); echo $a; // Act.Result: 7 // Exp. : 6 Case 3: $a = (int)((0.1+0.8) * 10); echo $a; // Act.Result: 9 // Exp.: 8 Hope you will give satisfactory feedback. Thanks! ------------------------------------------------------------------------ [2011-02-09 17:43:25] anon at anon dot anon PHP guys, will you please stop giving people broken links? ------------------------------------------------------------------------ [2011-02-09 14:18:33] johan...@php.net 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. . ------------------------------------------------------------------------ [2011-02-09 13:56:31] thipse_rahul at rediffmail dot com Description: ------------ Following code snippet -- Case 1: $a = (int)((0.1+0.7) * 10); echo $a; // Result: 7 (Wrong) should give 8 Case 2: $a = (int)((0.1+0.6) * 10); echo $a; // Result: 7 Case 3: $a = (int)((0.1+0.8) * 10); echo $a; // Result: 9 Test script: --------------- $a = (int)((0.1+0.7) * 10); echo $a; Expected result: ---------------- 8 Actual result: -------------- 7 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=53972&edit=1