Skip to content

Commit 47723af

Browse files
authored
gh-134887: Add references to locale module for locale-aware number formatting references in string module docs (GH-134888)
1 parent 3d2aa89 commit 47723af

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

Doc/library/string.rst

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,9 @@ of a number respectively. It can be one of the following:
472472
| | this option is not supported. |
473473
+---------+----------------------------------------------------------+
474474

475-
For a locale aware separator, use the ``'n'`` presentation type instead.
475+
For a locale-aware separator, use the ``'n'``
476+
:ref:`float presentation type <n-format-float>` or
477+
:ref:`integer presentation type <n-format-integer>` instead.
476478

477479
.. versionchanged:: 3.1
478480
Added the ``','`` option (see also :pep:`378`).
@@ -518,9 +520,14 @@ The available integer presentation types are:
518520
| | In case ``'#'`` is specified, the prefix ``'0x'`` will |
519521
| | be upper-cased to ``'0X'`` as well. |
520522
+---------+----------------------------------------------------------+
521-
| ``'n'`` | Number. This is the same as ``'d'``, except that it uses |
523+
| ``'n'`` | .. _n-format-integer: |
524+
| | |
525+
| | Number. This is the same as ``'d'``, except that it uses |
522526
| | the current locale setting to insert the appropriate |
523-
| | digit group separators. |
527+
| | digit group separators. Note that the default locale is |
528+
| | not the system locale. Depending on your use case, you |
529+
| | may wish to set :const:`~locale.LC_NUMERIC` with |
530+
| | :func:`locale.setlocale` before using ``'n'``. |
524531
+---------+----------------------------------------------------------+
525532
| None | The same as ``'d'``. |
526533
+---------+----------------------------------------------------------+
@@ -603,10 +610,15 @@ The available presentation types for :class:`float` and
603610
| | ``'E'`` if the number gets too large. The |
604611
| | representations of infinity and NaN are uppercased, too. |
605612
+---------+----------------------------------------------------------+
606-
| ``'n'`` | Number. This is the same as ``'g'``, except that it uses |
613+
| ``'n'`` | .. _n-format-float: |
614+
| | |
615+
| | Number. This is the same as ``'g'``, except that it uses |
607616
| | the current locale setting to insert the appropriate |
608-
| | digit group separators |
609-
| | for the integral part of a number. |
617+
| | digit group separators for the integral part of a |
618+
| | number. Note that the default locale is not the system |
619+
| | locale. Depending on your use case, you may wish to set |
620+
| | :const:`~locale.LC_NUMERIC` with |
621+
| | :func:`locale.setlocale` before using ``'n'``. |
610622
+---------+----------------------------------------------------------+
611623
| ``'%'`` | Percentage. Multiplies the number by 100 and displays |
612624
| | in fixed (``'f'``) format, followed by a percent sign. |

0 commit comments

Comments
 (0)