How to fix internal rounded in Python

55 Views Asked by At

I have a number 998001983016242063 and I want to take the exact square root of it. However, when I try to take the square root, python rounds my number to the integer part.

a=998001983016242063
print(a**0.5) # 999000492.0 Instead of 999 000 491,999999

I tried to use math.sqrt, pow, **0.5 and didn`t find a solution

1

There are 1 best solutions below

1
erip On

For arbitrary precision calculations, you can use decimal.Decimal:

>>> from decimal import Decimal
>>> a=998001983016242063
>>> Decimal(a).sqrt()
Decimal('999000491.9999999994994997460')