Shailendra Patel Shailendra Patel - 4 months ago 5x
Python Question

Python Division Error

The following division operation in Python returns:

>> 123456789012345678/2
>> 6.172839450617284e+16

While it should return:


Can you tell me the reason behind this and how to fix this? Is this the limit of Base 10 in Python? Because I heard that Python is only limited by the computer's memory.


Try this, if you are in python 3


In python 3, // refers to integer division (no reminder)

In General in python, however, / refers to division. To get floating point behavior in python < 3, do


Although the real question her is why python misses precision with large integer division. And i don't know why. But this solution might help solve your problem