Why (0.1 + 0.2 - 0.3) is 5.55111512313e-17?

Asked

Viewed 31 times

1

It seems pretty obvious to us humans that 0.1 + 0.2 - 0.3 is 0 but why when I ask the Python interpreter to perform the following operation:

print(0.1 + 0.2 - 0.3)

he returns 5.55111512313e-17?

It’s something to do with the precision of floats?

  • 2

    You have a number of questions/answers here about this: https://answall.com/questions/5642, https://answall.com/questions/219211 , https://answall.com/questions/38138 ...

  • 1
  • 2

    Thanks @Miguel, I was in doubt if closed as duplicate, but there are several examples here talking about the IEEE 754.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.