0

Why is it adding 2 here? What can I do to fix that?

>>> a=4.637421298803135e+16
>>> print("{0:.0f}".format(round(a,0)))
46374212988031352
>>> a=46374212988031350
>>> print("{0:.0f}".format(round(a,0)))
46374212988031352
Łukasz Rogalski
  • 22,092
  • 8
  • 59
  • 93
  • 1
    Possible duplicate of [Is floating point math broken?](http://stackoverflow.com/questions/588004/is-floating-point-math-broken) – Łukasz Rogalski Jul 11 '16 at 18:37
  • 2
    Doubles can only store about 15 digits of decimal precision. The first case is obvious. The second case defines the number as an int, but the `f` conversion calls `__float__` to convert before printing since that is what you requested. – Mad Physicist Jul 11 '16 at 18:39
  • How do I get it to stay a float then, print as a float and without a .xxx or e+16 in the result? – Beverly Williams Jul 11 '16 at 19:51

0 Answers0