0

With Python 3.4.3

int(1 / 1e-3)

1000

int(1 / 1e-4)

10000

int(1 / 1e-5)

99999

int(1 / 1e-6)

1000000

int(1 / 1e-7)

10000000

Bug or Feature? Any particular reason?

martineau
  • 119,623
  • 25
  • 170
  • 301
gota
  • 2,338
  • 4
  • 25
  • 45

1 Answers1

1

floating point numbers aren't exact. Only binary numbers are.

>>> '%.25f' % 1e-5
'0.0000100000000000000008180'
>>> '%.25f' % (1/1e-5)
'99999.9999999999854480847716331'

So 1/1e-5 is less than 100000 and int cuts off the fractal part. Converting to int, rounding is the answer:

>>> int(round(1/1e-5))
100000
Daniel
  • 42,087
  • 4
  • 55
  • 81