Eli5: Programmers, why does “0.15 == 0.150000000000000001” equals = True after 15 zeros?

211 views

Eli5: Programmers, why does “0.15 == 0.150000000000000001” equals = True after 15 zeros?

In: 13

5 Answers

Anonymous 0 Comments

To represent such a number as “0.150000000000000001” you need to use a data format known as “floating point”. Without getting into too many technical details, the floating point data format allows you to represent very small and very large numbers at the cost of accuracy. In a sense, a floating point number doesn’t represent a specific number, but a range of numbers.

When you take a number like 0.150000000000000001 and convert it to floating point format, the limitations on precision essentially round it down to 0.15.

EDIT:

As an addendum it is not technically accurate to say the computer rounds down to 0.15. Rather both 0.150000000000000001 and 0.15 become the same number in floating point format. According to [this calculator](https://www.h-schmidt.net/FloatConverter/IEEE754.html), they become 0.1500000059604644775390625

You are viewing 1 out of 5 answers, click here to view all answers.