Reputation: 1331
For example, how would do you make 1003.2
format to 1,003.20
?
I know I can use '%.2f' % 1003.2
to make it have two decimal places, but how do you also make the comma appear?
Upvotes: 1
Views: 129
Reputation: 369054
Using str.format
:
>>> '{:,.2f}'.format(1003.2)
'1,003.20'
The ','
format specification signals the use of a comma for a thousands separator.
Upvotes: 2