使用逗号分隔符格式化数字并在Python 2中舍入到2个小数位?

Ric*_*ard 13 python-2.7

我相信这一定是重复的,但我找不到一个明确的答案.

我如何输出2083525.34561作为2,083,525.35在Python 2?

我知道:

"{0:,f}".format(2083525.34561)
Run Code Online (Sandbox Code Playgroud)

它输出逗号但不循环.和:

"%.2f" % 2083525.34561
Run Code Online (Sandbox Code Playgroud)

哪一轮,但不添加逗号.

EdC*_*ica 30

添加一个带有位数的小数点,.2f请参阅文档:https://docs.python.org/2/library/string.html#format-specification-mini-language:

In [212]:
"{0:,.2f}".format(2083525.34561)

Out[212]:
'2,083,525.35'
Run Code Online (Sandbox Code Playgroud)