On this page
locale.format_string
Prev: locale.Error | Up: locale | Next: locale.getdefaultlocale
Rel: locale.atof, locale.atoi, locale.currency, locale.Error
Ref: docs.python.org — locale.format_string
Tags: #public #python3 #stdlib #locale
Import
import locale
from locale import format_string
Signature & Overview
locale.format_string(f, val, grouping=False, monetary=False)
Formats a string in the same way that the % formatting would use, but takes the current locale into account.
Usage
import locale
assert locale.format_string("%.2f", 1234.5, grouping=True).endswith("50")
Gotchas
- Replaces removed
locale.format(): Supports%-style format strings with locale decimal points and grouping.
REPL Inspect
from locale import format_string
help(format_string)
Linked from
Related notes
- tuts/python3/stdlib_module/locale/atof Linked here; links to this page; shared tags: #locale, #stdlib
- tuts/python3/stdlib_module/locale/atoi Linked here; links to this page; shared tags: #locale, #stdlib
- tuts/python3/stdlib_module/locale/currency Linked here; links to this page; shared tags: #locale, #stdlib
- tuts/python3/stdlib_module/locale/Error Linked here; links to this page; shared tags: #locale, #stdlib
- tuts/python3/stdlib_module/locale/getdefaultlocale Linked here; links to this page; shared tags: #locale, #stdlib
- tuts/python3/stdlib_module/locale Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/locale/getencoding shared tags: #locale, #stdlib
- tuts/python3/stdlib_module/locale/getlocale shared tags: #locale, #stdlib
- tuts/python3/stdlib_module/locale/getpreferredencoding shared tags: #locale, #stdlib
- tuts/python3/stdlib_module/locale/localeconv shared tags: #locale, #stdlib