Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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: