Back

Why can’t Python count properly?

The truth behind 0.1 + 0.2 in Python

28 October 2026

Floating point “errors” explained in python

If you’ve ever typed 0.1 + 0.2 into Python and expected a neat 0.3, only to be greeted with 0.30000000000000004, you’re not alone. It looks like Python has forgotten how numbers work – but in reality, it’s doing exactly what it’s designed to do.
This is one of the most common surprises in programming, and it all comes down to how computers represent numbers.

Binary vs decimal: Why the confusion happens

We use base-10 (decimal) every day, but computers use base-2 (binary). Because of this, many simple decimal numbers – like 0.1 – can’t be represented exactly in binary.
Instead, computers store these values using the IEEE 754 Floating-Point Standard, which breaks numbers into a sign, mantissa, and exponent. This allows for incredibly efficient calculations across science, graphics, and simulations, but it comes with a small trade-off: rounding.
Just like 1/3 becomes 0.3333… in decimal, 0.1 becomes an endlessly repeating binary fraction. Computers can’t store infinity, so they round to the closest possible approximation.

So why does 0.1 + 0.2 look wrong?

When you add 0.1 and 0.2 in Python, you’re not adding the exact values you think you are. You’re adding two tiny binary approximations. The result is extremely close to 0.3 – just not perfectly identical.
Python isn’t being wrong here; it’s being honest. It shows you the true stored value rather than hiding the small rounding differences.

Is this just a Python problem?

Not at all. This behaviour is standard across almost all programming languages that use floating-point arithmetic, including Java, JavaScript, and C++. It’s simply how modern computing works.
When precision really matters – such as in finance – developers use decimal libraries or arbitrary-precision arithmetic to avoid these tiny inaccuracies.

Computers are honest, sometimes too honest

The key takeaway? Python can absolutely count. The real lesson is that computers are incredibly powerful, but they don’t always think in the same neat decimals we do.
Sometimes they just insist on showing their working — even when we’d rather they didn’t.

Want to know more? Kat, our Craig’n’Dave Lesson Hacker, explains all.

For more Lesson Hacker videos, check out the Craig’n’Dave YouTube playlist HERE.

Visit our website to explore more cutting-edge tech news in the computer science world!

 

Related posts

Why does AI struggle to draw hands?

AI image generators can create stunningly realistic scenes, but they still struggle with one surprisingly human detail: hands. From extra fingers to warped joints, the issue reveals a lot about how machine learning models actually “see” the world.

18 November 2026

What should GCSE Computing look like in the future?

AQA want to hear from the teachers who know the subject and understand what works in the classroom. Share your […]

16 November 2026

Would thin phones still smash?

Ultra-thin phones may look sleek and futuristic, but physics has other ideas when it comes to durability. Once you strip away thickness, you also strip away protection, making drops a lot more dramatic than design renders suggest.

11 November 2026

The school initiatives worth keeping and the ones worth leaving behind

Are school policies and classroom initiatives genuinely improving learning, or are they creating unnecessary work for teachers? We explore why purpose, consistency and common sense matter more than simply ticking boxes.

6 November 2026

How do recommendation algorithms decide what you see?

Ever wondered how TikTok, YouTube, and Instagram seem to know exactly what you’ll watch next? Recommendation algorithms use your behaviour – not your opinions – to predict what you’ll engage with in real time.

4 November 2026

Beyond the IDE: programming lessons in the age of AI

One of the most persistent challenges in a programming classroom is knowing what every student is doing at any given […]

23 October 2026

If a NOT gate turns zero into one, where does that one come from?

How does a NOT gate turn a 0 into a 1 without creating something from nothing? Discover how voltage, transistors and digital logic work together to power the technology inside every modern computer.

15 October 2026

Ofsted after the Big Listen: have the rules changed, or just the packaging?

Ofsted has changed its inspection framework, but many school leaders question whether it has changed the culture surrounding inspection. We explore whether report cards can rebuild trust, reduce pressure and create an accountability system that genuinely helps schools improve.

9 October 2026

Should I make my own resources?

Should teachers really be making all their own resources? We explore the balance between creating, buying and adapting resources — and why thoughtful planning matters more than who made them.

5 October 2026