0

I was playing with the python command line, and saw that when I type

1.2 + 0.6

I get 1.7999999999999998, but when I type

1.2 + 0.5

I get 1.7,
Moreover, 1.2 + 0.9 gives 2.1000000000000001. Does anyone know what's happening in here? I'm just curious...

Ehsan
  • 4,334
  • 7
  • 39
  • 59
  • 1
    that has something to do with the fact how floats are saved in python http://stackoverflow.com/questions/455612/python-limiting-floats-to-two-decimal-points – Florian Groetzner Nov 13 '13 at 22:00
  • 4
    It has to do with how floating point values are represented in binary. This is not something unique to Python, but it does get seen more there. The following is a good description of what is going on: http://www.exploringbinary.com/why-0-point-1-does-not-exist-in-floating-point/. – K.Niemczyk Nov 13 '13 at 22:00
  • 4
    Duplicate of oh-so-many questions, e.g. stackoverflow.com/questions/19433508/python-2-23-0-6-6000000000000005. – rlms Nov 13 '13 at 22:02

0 Answers0