Python Output Currency Format data __python

Source: Internet
Author: User
Tags iterable locale locale setting
Before data format is set:
Import locale
num = 123456789
print (Locale.format ("%.2f", A, 1))
Output:

123456789.00

To set the data output format:

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

"Chinese (Simplified) _people ' s Republic of china.936"

After data format is set:

Print (Locale.format ("%.2f", num, 1))
Output:

123,456,789.00


Function Description:

Locale. setlocale (category [, Locale])

If locale is given and not None,setlocale () modifies the locale to setting for thecategory. The available categories are listed in the data Description Below.locale ' May is a string, or an iterable of two strings (l Anguage 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 to account.

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.