reimei Posted October 20, 2013 Share Posted October 20, 2013 (edited) Hello I'm confused with the behavior of the following code: $t = 9.8; $deltaT = 0.1; while($t < 10) { $t = $t+ $deltaT; echo $t.'<br />'; } For $t = 9.8, it echos the correct result(the last number it echos is 10), but for $t smaller than 9.8, for example $t = 9.5, the last number it echos is 10.1. why?! Edited October 20, 2013 by reimei Quote Link to comment https://forums.phpfreaks.com/topic/283125-abnormal-behavior-of-php-code/ Share on other sites More sharing options...
Ch0cu3r Posted October 20, 2013 Share Posted October 20, 2013 (edited) Read the following (red warning) http://php.net/manual/en/language.types.float.php Edited October 20, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/283125-abnormal-behavior-of-php-code/#findComment-1454660 Share on other sites More sharing options...
reimei Posted October 20, 2013 Author Share Posted October 20, 2013 (edited) You taught me a new thing. Thanks alot Edited October 20, 2013 by reimei Quote Link to comment https://forums.phpfreaks.com/topic/283125-abnormal-behavior-of-php-code/#findComment-1454662 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.