Nagendra Murti
Nagendra Murti

Reputation: 33

How to suppress the exponential format when using decimal module in Python

I am writing python code that requires precision up to 108 digits beyond the decimal point. For this, I am using the "decimal" module. In some calculations (example below), I get the result in the exponential format. Example:

from decimal import *
getcontext().prec=100
result1 = Decimal(387) / Decimal(1577917828000)
#results are returned in JSON

The resulting value is 2.452599198340510796231399192987633827532874544592571774909941634806093337326815474702907026157258171E-10 However, I need this in the normal (float?) format without the E-10. Any suggestions?

Upvotes: 1

Views: 97

Answers (1)

Nott
Nott

Reputation: 313

You can try this,

from decimal import *
getcontext().prec=100
result1 = Decimal(387) / Decimal(1577917828000)
print('{:f}'.format(result1))

You need to use this,

'{:f}'.format(result1)

Upvotes: 2

Related Questions