Q:

python convert long floats to usd

def as_currency(amount):
    if amount >= 0:
        return '${:,.2f}'.format(amount)
    else:
        return '-${:,.2f}'.format(-amount)
0
>>> '${:,.2f}'.format(1234.5)
'$1,234.50'
0

Tags

New to Communities?

Join the community