【发布时间】:2017-08-03 18:22:52
【问题描述】:
Python 3.6(又名 PEP 498)引入了我喜欢的格式化字符串。在某些情况下,我们必须输出用户难以阅读的大量数字。我在下面的示例中使用了区域设置分组。我想知道是否有更好的方法来格式化格式化字符串中的大量数字?
import locale
locale.setlocale(locale.LC_ALL, 'en_US')
count = 80984932412380
s = f'Total count is:{locale.format("%d", count, grouping = True)}'
>>> s
'Total count is:80,984,932,412,380'
非常感谢您的帮助!
【问题讨论】:
标签: python string formatting python-3.6