Converting a very small python Decimal to a string of unscientific notations

I am using the Python Decimal class for accurate floating point arithmetic. I need to convert the number of results sequentially to a standard notation number as a string. However, very small decimal numbers are displayed 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 do I get str(d)to return '0.000000001'?

+4
source share
1 answer
'{:f}'.format(d)
Out[12]: '0.000000001'
+5
source

Source: https://habr.com/ru/post/1532364/


All Articles