Python 格式化数字之千分位
目录
不涉及本地化
'{:,}'.format(value) # For Python ≥2.7
f'{value:,}' # For Python ≥3.6
涉及本地化
import locale
locale.setlocale(locale.LC_ALL, '') # '' 空字符自动选择, 或者指定,例如 'en_US.UTF-8'
'{:n}'.format(value) # For Python ≥2.7
f'{value:n}' # For Python ≥3.6
参考文章
- Format Specification Mini-Language
- https://stackoverflow.com/questions/1823058/how-to-print-a-number-using-commas-as-thousands-separators
阿里云百炼大模型
9折优惠 + 所有模型各百万免费Token →