I’m using python 3, i want calculate: 18446744073709550592 / 65536, python get output:
281474976710656
But true result is:
281474976710655.984375
It is automatically rounded, is there any way to calculate it accurately?
- use python’s decimal module to avoid rounding errors.
from decimal import Decimal
numerator = Decimal('18446744073709550592')
denominator = Decimal('65536')
result = numerator / denominator
print(result)