带空格的python格式字符串千位分隔符 [英] python format string thousand separator with spaces
本文介绍了带空格的python格式字符串千位分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用千位分隔符打印数字,可以使用python格式字符串:
For printing number with thousand separator, one can use the python format string :
'{:,}'.format(1234567890)
但是我如何指定我想要一个空格作为千位分隔符?
But how can I specify that I want a space for thousands separator?
推荐答案
如果您不想弄乱 locale
,这里有一个糟糕但简单的解决方案:
Here is bad but simple solution if you don't want to mess with locale
:
'{:,}'.format(1234567890.001).replace(',', ' ')
这篇关于带空格的python格式字符串千位分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文