Python Add Comma Into Number String

Using Python v2, I have a value running through my program that puts out a number rounded to 2 decimal places at the end:

like this:

print ("Total cost is: ${:0.2f}".format(TotalAmount))

Is there a way to insert a comma value every 3 digits left of the decimal point?

Ie: 10000.00 becomes 10,000.00 or 1000000.00 becomes 1,000,000.00

Thanks for any help.


In Python 2.7 or above, you can use

print ("Total cost is: ${:,.2f}".format(TotalAmount))

This is documented in PEP 378.

(From your code, I can't tell which Python version you are using.)