Python 輸出貨幣格式資料__Python

來源:互聯網
上載者:User
未設定資料格式前:
import localenum = 123456789print(locale.format("%.2f", a, 1))
Output:

123456789.00

設定資料輸出格式:

 locale.setlocale(locale.LC_ALL, '') # Set the locale for your system
Output:

"Chinese (Simplified)_People's Republic of China.936"

設定資料格式後:

print(locale.format("%.2f", num, 1))
Output:

123,456,789.00


函數介紹:

locale. setlocale ( category [, locale ] )

If locale is given and not None,setlocale() modifies the locale setting for thecategory. The available categories are listed in the data description below.locale may be a string, or an iterable of two strings (language code and encoding). If it’s an iterable, it’s converted to a locale name using the locale aliasing engine. An empty string specifies the user’s default settings. If the modification of the locale fails, the exception Error is raised. If successful, the new locale setting is returned.

If locale is omitted or None, the current setting forcategory is returned.

locale. format ( format, val [, grouping [, monetary ] ] )

Formats a number val according to the current LC_NUMERIC setting. The format follows the conventions of the% operator. For floating point values, the decimal point is modified if appropriate. Ifgrouping is true, also takes the grouping into account.

If monetary is true, the conversion uses monetary thousands separator and grouping strings.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.