如何在Python 3中为数字添加逗号?

时间:2015-04-09 02:54:38

标签: python

如何在Python 3中为数字添加逗号?

>>> income = 50000
>>> print("Your income tax is ${0}.".format(income))
Your income tax is $50000.

只是想知道如何打印$50,000

我的问题不重复 如果我将第二行更改为print("Your income tax is **${:,.2f}.".format(income))。我收到$50,000.00,但我不希望在小数点后加上任何**额外的零。

1 个答案:

答案 0 :(得分:1)

试试这个:

print("Your income tax is ${:,}".format(income))