2

I have a very strange problem in python. I tried running the following code in the console:

>>> str(23438.67709815)
'23438.6770982'
>>> str(22222.67709815)
'22222.6770982'
>>> str(11111.67709815)
'11111.6770981'

The last number is strange; when should it be carried, and another not?

Ébe Isaac
  • 11,563
  • 17
  • 64
  • 97
Y.Devil
  • 59
  • 3
  • I don't think this is an exact duplicate of the linked question, because that would require the OP to know that the issue is caused by floats' representations of numbers. – acdr Jun 09 '17 at 09:00
  • Hmm, it has something to do with 16384 (0x4000)... – CristiFati Jun 09 '17 at 09:00
  • `>>> '%.20f' % 22222.67709815` `'22222.67709815000125672668'` `>>> '%.20f' % 11111.67709815` `'11111.67709814999943773728'` – Ignacio Vazquez-Abrams Jun 09 '17 at 09:08
  • @IgnacioVazquez-Abrams: I know that the cause is float representation. But OP might not. Hence, just linking her/him to a question on float representation might not help. (I mean, apart from me mentioning it just now.) – acdr Jun 09 '17 at 09:23

0 Answers0