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

0.1 + 0.1 + 0.1 - 0.3

Im very confused how this dosent equal 0 like it would in normal math

2 Answers

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

Hi, Nick Evershed! This is true in many different programming languages. The key thing to understand here is that computers don't deal in base 10. They deal in binary. So everything you put in must first be converted to binary then do the arithmetic, then converted back to base 10.

In this process, there is often what is known as a "floating point error". There will always be a small discrepancy when doing these translations back and forth. They can be mitigated somewhat, but not eliminated.

Here's a thorough article on the matter. However, it's a bit tough to read. The main point is that shifting back and forth between base 10 and base 2 creates small discrepancies.

Hope this helps! :sparkles:

Remember My Friend!! python is not a calculator. it can make mistakes. Nick Evershed