locale.format_string()
locale.format_string() is a Python function in the Locale Module category. Formats a number according to the current locale. The syntax is locale.format_string(fmt, val, grouping=False, monetary=False). Returns: Formatted string. A typical example: locale.setlocale(locale.LC_NUMERIC, "de_DE")
locale.format_string("%.2f", 1234.56) # "1.234,56". A close sibling is locale.setlocale(), which sets the locale for a category (LC_ALL, LC_TIME, LC_NUMERIC, etc.). A close sibling is locale.getlocale(), which returns the current locale setting as (language, encoding). A close sibling is locale.getdefaultlocale(), which returns the default locale from environment variables. A close sibling is locale.strcoll(), which compares two strings according to the current LC_COLLATE locale. More about this category: Internationalization — setlocale, getlocale, currency, strcoll. Related Locale Module entries: locale.setlocale(), locale.getlocale(), locale.getdefaultlocale(), locale.strcoll(), locale.strxfrm(), locale.currency(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details. You can try locale.format_string() immediately in the Python playground, look up unfamiliar terms in the glossary, or return to the Python Reference homepage.