Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python

Sandra Olmesdahl
seal-mask
.a{fill-rule:evenodd;}techdegree
Sandra Olmesdahl
Front End Web Development Techdegree Student 2,522 Points

Why are float calculations inaccurate?

Quick one - how come the question 0.1 + 0.1 + 0.1 - 0.3 does not come up with an exact answer? Surely (as you point out), this inaccuracy can have some pretty serious side effects? Is this due to the original parameters around the Python language, or is it just one of "those" idiosyncrasies?

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! I'm not sure what you mean by "those" idiosyncrasies, but the topic you just touched upon is very likely bigger than you think and by no means exclusive to Python. Among other things, you will need a good foundation in math and number theory to understand the answer. But I might suggest this article from Oracle or this one.

The problem is not so much with Python or really any other computer language. The problem lies in the representation of the numbers themselves. Remember, at the end of all this everything is still just 0s and 1s. This is where the problem lies. You are representing a decimal value in binary form and some inaccuracy will occur as a result.

Hope this helps! :sparkles: