Shailendra Patel Shailendra Patel - 2 years ago 119
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download