0
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print(111111111111111111/10)
1.1111111111111112e+16
>>> print(int(111111111111111111/10))
11111111111111112
>>>

Refering to the above snippet, Can someone please help me understand why 111111111111111111/10 returns 11111111111111112 instead of 11111111111111111?

thunderbird
  • 2,715
  • 5
  • 27
  • 51
  • `11111111111111111.0 == 11111111111111112.0`. Floating point is wild. Use `//` for precise integer division, though. – Ry- Jul 15 '19 at 07:51
  • @Ry- so i guess, `math.floor()` and others wont help as well in such cases? – thunderbird Jul 15 '19 at 07:55
  • Correct. If you have two integers and want to divide them for an exact result, you have to use `//`. – Ry- Jul 15 '19 at 08:54

1 Answers1

3

Use floor division:

>>> 111111111111111111//10
11111111111111111
>>> 
U13-Forward
  • 69,221
  • 14
  • 89
  • 114