Python string formatting
Published on December 8, 2011
Because I can never find it when I want to, here’s how to quickly format a US dollar amount:
>>> from decimal import Decimal
>>> '{:,.2f}'.format(Decimal('12312123.1231212'))
'12,312,123.12'
This is for Python 2.7 and above.
Thanks, Raymond!