Building on @JustinBarber's example and noting @eric.frederich's comment, if you want to format negative values like -$1,000.00
rather than $-1,000.00
and don't want to use locale
:
def as_currency(amount):
if amount >= 0:
return '${:,.2f}'.format(amount)
else:
return '-${:,.2f}'.format(-amount)