0
    >>> 8.7+4.1
    12.799999999999999
    >>> 2.0+3.2
    5.2
    >>> 3.7+5.1
    8.8

I don't understand why the first addition returns a repeating number and then why the other doesn't. Using Python 3.6.1 terminal

Frank
  • 9
  • 1
  • Store those `8.7` and `4.1` into a variable and then print them out the same way. Then add these two values. – Jongware Jan 14 '18 at 18:18
  • Ok sure but why does adding 8.7 and 4.1 results in a repeating number and the others don't ? what's so special about them – Frank Jan 14 '18 at 18:22
  • The floating point format used by most implementations of Python do not support "repeating numbers". It's just a coincidence that you are shown all 9s here. Read https://docs.python.org/2/tutorial/floatingpoint.html for a longer explanation. My favorite line in there is "Note that this is in the very nature of binary floating-point: this is not a bug in Python, and it is not a bug in your code either." – Jongware Jan 14 '18 at 18:26

0 Answers0