dmi_
dmi_

Reputation: 1257

Converting a very small python Decimal into a non-scientific notation string

I am using the Python Decimal class for precise floating-point arithmetic. I need to convert the result number consistently into a standard notation number as a string. However, very small decimal numbers are rendered in scientific notation by default.

>>> from decimal import Decimal
>>> 
>>> d = Decimal("0.000001")
>>> d
Decimal('0.000001')
>>> str(d)
'0.000001'
>>> d = Decimal("0.000000001")
>>> d
Decimal('1E-9')
>>> str(d)
'1E-9'

How would I get str(d) to return '0.000000001'?

Upvotes: 9

Views: 3828

Answers (1)

m.wasowski
m.wasowski

Reputation: 6386

'{:f}'.format(d)
Out[12]: '0.000000001'

Upvotes: 11

Related Questions