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 ??? Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
juhasamy Posted November 15, 2007 Author Share Posted November 15, 2007 Thanks. Quote Link to comment 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.