How can I display Decimal('40800000000.00000000000000')
as '4.08E+10'
?
I've tried this:
>>> '%E' % Decimal('40800000000.00000000000000')
'4.080000E+10'
But it has those extra 0's.
number-formattingpythonscientific-notationstring-formatting
How can I display Decimal('40800000000.00000000000000')
as '4.08E+10'
?
I've tried this:
>>> '%E' % Decimal('40800000000.00000000000000')
'4.080000E+10'
But it has those extra 0's.
Best Answer
In your '40800000000.00000000000000' there are many more significant zeros that have the same meaning as any other digit. That's why you have to tell explicitly where you want to stop.
If you want to remove all trailing zeros automatically, you can try: