locale module accesses a database of culture specific data formats : Locale « Language Basics « Python






locale module accesses a database of culture specific data formats



#locale module accesses a database of culture specific data formats. The 
#grouping 
#attribute of locale's format function provides a direct way of formatting numbers 
#with group separators:

import locale
locale.setlocale(locale.LC_ALL, 'English_United States.1252')

conv = locale.localeconv()          # get a mapping of conventions
x = 1234567.8

locale.format("%d", x, grouping=True)

locale.format("%s%.*f", (conv['currency_symbol'],conv['frac_digits'], x), grouping=True)

           
       








Related examples in the same category