juhasamy Posted November 15, 2007 Share Posted November 15, 2007 $x = -0.2; $x += 0.1; print $x . '<br>'; $x += 0.1; print $x . '<br>'; $x += 0.1; print $x . '<br>'; => -0.1 0 0.1 $x = -0.3; $x += 0.1; print $x . '<br>'; $x += 0.1; print $x . '<br>'; $x += 0.1; print $x . '<br>'; $x += 0.1; print $x . '<br>'; => -0.2 -0.1 2.77555756156E-17 0.1 ??? Link to comment https://forums.phpfreaks.com/topic/77481-number-addition/ Share on other sites More sharing options...
adam291086 Posted November 15, 2007 Share Posted November 15, 2007 What are you trying to do, we can't help without explainations. Link to comment https://forums.phpfreaks.com/topic/77481-number-addition/#findComment-392234 Share on other sites More sharing options...
juhasamy Posted November 15, 2007 Author Share Posted November 15, 2007 I mean: Is there a bug in PHP? Link to comment https://forums.phpfreaks.com/topic/77481-number-addition/#findComment-392237 Share on other sites More sharing options...
adam291086 Posted November 15, 2007 Share Posted November 15, 2007 i am not sure. Is it supposed to text the value $x and add whatever number and then print it out? Link to comment https://forums.phpfreaks.com/topic/77481-number-addition/#findComment-392238 Share on other sites More sharing options...
kenrbnsn Posted November 15, 2007 Share Posted November 15, 2007 You're dealing with the classic problem of converting a floating point number from the internal representation in binary to decimal. The value "2.77555756156E-17" is really zero for all pratical purposes. It's not a bug in PHP, it's just how computers work... Ken Link to comment https://forums.phpfreaks.com/topic/77481-number-addition/#findComment-392245 Share on other sites More sharing options...
adam291086 Posted November 15, 2007 Share Posted November 15, 2007 OH i see now, i thoght it was werid. Everything looked right. I learn so much from this board. More than what i have learned in my degree. Link to comment https://forums.phpfreaks.com/topic/77481-number-addition/#findComment-392247 Share on other sites More sharing options...
juhasamy Posted November 15, 2007 Author Share Posted November 15, 2007 Thanks. Link to comment https://forums.phpfreaks.com/topic/77481-number-addition/#findComment-392255 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.