int(10000000000000000000000000000000000/10**10) It should return the exact value like 10000000000000000000000, but the returned value is 999999999999999983222784. What is the reason behind it??
Asked
Active
Viewed 142 times
-2
-
https://docs.python.org/3/tutorial/floatingpoint.html – Mitch Wheat May 25 '20 at 03:27
-
2In python 3 you have to use `//` to do integer division. Try `int(10000000000000000000000000000000000//10**10)` – Nick May 25 '20 at 03:28
1 Answers
1
The floating point division operator (/
) produces an inexact result. Converting it to an int
after the fact doesn't fix that.
If you use the integer division operator (//
) you get an exact integer result:
>>> 10000000000000000000000000000000000//10**10
1000000000000000000000000

Samwise
- 68,105
- 3
- 30
- 44