Documentation
I was trying out the option of using n in a format specifier to use locale-aware thousands and decimal separators. I was surprised to see it didn't do anything on my machine, despite locale.getlocale() returning what I expected:
>>> import locale
>>> locale.getlocale()
('en_US', 'UTF-8')
>>> x = 12345
>>> f'{x:n}'
'12345'
I did some more digging and realized I needed to do locale.setlocale(locale.LC_NUMERIC, 'en_US') first, which was neither obvious nor mentioned in the documentation where it introduces the n option:
>>> import locale
>>> locale.setlocale(locale.LC_NUMERIC, 'en_US')
>>> x = 12345
>>> f'{x:n}'
'12,345'
I propose adding a mention that the locale.LC_NUMERIC must be set in this section as a helpful cross-reference.
Linked PRs
Documentation
I was trying out the option of using
nin a format specifier to use locale-aware thousands and decimal separators. I was surprised to see it didn't do anything on my machine, despitelocale.getlocale()returning what I expected:I did some more digging and realized I needed to do
locale.setlocale(locale.LC_NUMERIC, 'en_US')first, which was neither obvious nor mentioned in the documentation where it introduces thenoption:I propose adding a mention that the
locale.LC_NUMERICmust be set in this section as a helpful cross-reference.Linked PRs
localemodule for locale-aware number formatting references instringmodule docs #134888