-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-134887: Add references to locale
module for locale-aware number formatting references in string
module docs
#134888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -469,7 +469,10 @@ of a number respectively. It can be one of the following: | |
| | this option is not supported. | | ||
+---------+----------------------------------------------------------+ | ||
|
||
For a locale aware separator, use the ``'n'`` presentation type instead. | ||
For a locale-aware separator, use the ``'n'`` presentation type instead. | ||
Note that the locale setting for numeric values must first be set using | ||
the :mod:`locale` module, for example, | ||
``locale.setlocale(locale.LC_NUMERIC, 'en_US')``. | ||
|
||
.. versionchanged:: 3.1 | ||
Added the ``','`` option (see also :pep:`378`). | ||
|
@@ -517,7 +520,10 @@ The available integer presentation types are: | |
+---------+----------------------------------------------------------+ | ||
| ``'n'`` | Number. This is the same as ``'d'``, except that it uses | | ||
| | the current locale setting to insert the appropriate | | ||
| | digit group separators. | | ||
| | digit group separators. Note that the default locale is | | ||
| | not the system locale, and therefore, you must set, at a | | ||
| | minimum, the ``LC_NUMERIC`` category (see the | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't true, is it? I'm referring to the wording "must set": shouldn't it be "can set". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On my machine, nothing happens if I use FWIW, I'm seeing that the C locale seems to be very minimal and doesn't have a thousands separator. Since that is what the default is, instead of the system locale, the thousands separator won't be set until the user sets |
||
| | :mod:`locale` module for more information). | | ||
+---------+----------------------------------------------------------+ | ||
| None | The same as ``'d'``. | | ||
+---------+----------------------------------------------------------+ | ||
|
@@ -599,8 +605,11 @@ The available presentation types for :class:`float` and | |
+---------+----------------------------------------------------------+ | ||
| ``'n'`` | Number. This is the same as ``'g'``, except that it uses | | ||
| | the current locale setting to insert the appropriate | | ||
| | digit group separators | | ||
| | for the integral part of a number. | | ||
| | digit group separators for the integral part of a | | ||
| | number. Note that the default locale is not the system | | ||
| | locale, and therefore, you must set, at a minimum, the | | ||
| | ``LC_NUMERIC`` category (see the :mod:`locale` module | | ||
| | for more information). | | ||
+---------+----------------------------------------------------------+ | ||
| ``'%'`` | Percentage. Multiplies the number by 100 and displays | | ||
| | in fixed (``'f'``) format, followed by a percent sign. | | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why refer to this here? At most it just belongs in the
n
section.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I was troubleshooting why this wasn't working for me, I searched this page in the docs for "locale aware" and "locale-aware" – this was the only hit, so I put this here as well to make sure that all spots a person may learn about this in the docs include all the information to use it directly. Most people won't read the entire page in the docs before using something.