问题描述
我希望使用 Python 将 188518982.18 等数字格式化为 £188,518,982.18.
I am looking to format a number like 188518982.18 to £188,518,982.18 using Python.
我该怎么做?
推荐答案
查看 locale 模块.
这会进行货币(和日期)格式设置.
This does currency (and date) formatting.
>>> import locale >>> locale.setlocale( locale.LC_ALL, '' ) 'English_United States.1252' >>> locale.currency( 188518982.18 ) '$188518982.18' >>> locale.currency( 188518982.18, grouping=True ) '$188,518,982.18'