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.