Welcome to the Treehouse Community
Looking to learn something new?
Why does Python produce incorrect floating point math results?
One of the beginner Python lessons showcases this problem
and Python produces the result of
Why? And why isn't this fixed in Python after all these years? Seems like so much logic would fail expected from this kind of thing and would require so much handling.
Is this by design to have bad results and how does this make sense?
This is because of the fact that computers, and therefore also python, use binary. The 0.300...004 is an approximation in binary.
For me trying the same thing does yield the correct answer, so some changes may havd been made through different versions.
Craig Webber5,677 Points
computers are actually not very good at exact maths. If you want to look deeper into why I suggest watching the CS50 videos they are great. https://www.youtube.com/channel/UCcabW7890RKJzL968QWEykA