reimei Posted October 20, 2013 Share Posted October 20, 2013 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?! 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 Read the following (red warning) http://php.net/manual/en/language.types.float.php 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 You taught me a new thing. Thanks alot 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
Archived
This topic is now archived and is closed to further replies.