Vinayak Singla Vinayak Singla -4 years ago 69
Python Question

How to find floor on big floating point numbers?

How could I correctly find

floor(a*n)
in python where
n
is a very large floating point number?

I tried it using
Decimal
module but

Deciaml(1.1) * Decimal(123456789123456789123456789)


It is not giving right answer.

Answer Source

You can't use a float to construct a Decimal, the precision has already been lost. Initialize it with a string:

>>> Decimal(1.1) * Decimal(123456789123456789123456789)
Decimal('135802468035802479000968054.4')
>>> Decimal('1.1') * Decimal(123456789123456789123456789)
Decimal('135802468035802468035802467.9')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download