本文介紹了如何打印帶有數千個分隔符的浮點數?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
如何格式化十進制數,以便 32757121.33
顯示為 32.757.121,33
?
How can I format a decimal number so that 32757121.33
will display as 32.757.121,33
?
推薦答案
使用 locale.format()
:
>>> import locale
>>> locale.setlocale(locale.LC_ALL, 'German')
'German_Germany.1252'
>>> print(locale.format('%.2f', 32757121.33, True))
32.757.121,33
您可以將語言環境更改限制為顯示數值(使用 locale.format()
、locale.str()
等時)并保留其他語言環境設置不受影響:
You can restrict the locale changes to the display of numeric values (when using locale.format()
, locale.str()
etc.) and leave other locale settings unaffected:
>>> locale.setlocale(locale.LC_NUMERIC, 'English')
'English_United States.1252'
>>> print(locale.format('%.2f', 32757121.33, True))
32,757,121.33
>>> locale.setlocale(locale.LC_NUMERIC, 'German')
'German_Germany.1252'
>>> print(locale.format('%.2f', 32757121.33, True))
32.757.121,33
這篇關于如何打印帶有數千個分隔符的浮點數?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!