简体   繁体   English

Python:数千个分隔符 - 旧格式语法

[英]Python: Thousands Separator - old Formatting Syntax

With the new formatting syntax, Python can easily be made to print a thousands separator: 使用新的格式化语法,可以轻松地使用Python打印数千个分隔符:

print ("{0:,.2f} Euro".format(myVariable))

So the comma takes care for this. 所以逗号会照顾这个。

How can this be done with the old syntax - without using locale? 如何使用旧语法完成此操作 - 不使用语言环境?

print ("%.2f Euro" % myVariable)

printf -style formatting does not support thousand separator. printf style格式不支持千位​​分隔符。

You need to build a string with thousand separator: 你需要用千位分隔符构建一个字符串:

>>> amount = 12345
>>> '%s Euro' % format(amount, ',.2f')
'12,345.00 Euro'

Built-in function format uses the same Format Specification Mini-Language that str.format uses. 内置函数format使用与str.format相同的格式规范迷你语言

If you can't use format , see this question for alternatives. 如果您不能使用format ,请参阅此问题以获取替代方案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python 千位分隔符格式与不同的字符,而不使用语言环境 - python thousands separator formatting with different character without using locale python .format指定字段宽度中的千位分隔符 - python .format thousands separator in specified field width 在注释值中添加千位逗号分隔符 - Python - Adding thousands comma separator to annotated values - Python 用数千个分隔符和字体大小格式化y轴matplotlib - Formatting y-axis matplotlib with thousands separator and font size 格式化德语的刻度标签,即用一个点作为千位分隔符,逗号作为小数点分隔符 - Formatting tick label for the German language, i.e., with a point as a thousands separator and comma as a decimal separator Python Pandas read_csv千位分隔符不起作用 - python pandas read_csv thousands separator does not work Python读取逗号分隔的txt文件,具有数千个分隔符 - Python read comma separated txt file having thousands separator 如何使用逗号打印数字作为Python / Django中的千位分隔符和小数位 - How to print number with commas as thousands separator and decimal places in Python/Django 如何使用Python在字符串中使用空格分隔符识别数字? - How can I identify numbers with space separator for thousands in a string with Python? 如何将数千个分隔符添加到已在python中转换为字符串的数字? - how to add thousands separator to a number that has been converted to a string in python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM