Skip to content

Commit 792a552

Browse files
[3.13] gh-134887: Add references to locale module for locale-aware number formatting references in string module docs (GH-134888) (GH-150122)
(cherry picked from commit 47723af) Co-authored-by: Stefanie Molin <24376333+stefmolin@users.noreply.github.com>
1 parent 23fcb48 commit 792a552

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
@@ -457,7 +457,9 @@ It can be one of the following:
457457
| | this option is not supported. |
458458
+---------+----------------------------------------------------------+
459459

460-
For a locale aware separator, use the ``'n'`` presentation type instead.
460+
For a locale-aware separator, use the ``'n'``
461+
:ref:`float presentation type <n-format-float>` or
462+
:ref:`integer presentation type <n-format-integer>` instead.
461463

462464
.. versionchanged:: 3.1
463465
Added the ``','`` option (see also :pep:`378`).
@@ -508,9 +510,14 @@ The available integer presentation types are:
508510
| | In case ``'#'`` is specified, the prefix ``'0x'`` will |
509511
| | be upper-cased to ``'0X'`` as well. |
510512
+---------+----------------------------------------------------------+
511-
| ``'n'`` | Number. This is the same as ``'d'``, except that it uses |
513+
| ``'n'`` | .. _n-format-integer: |
514+
| | |
515+
| | Number. This is the same as ``'d'``, except that it uses |
512516
| | the current locale setting to insert the appropriate |
513-
| | digit group separators. |
517+
| | digit group separators. Note that the default locale is |
518+
| | not the system locale. Depending on your use case, you |
519+
| | may wish to set :const:`~locale.LC_NUMERIC` with |
520+
| | :func:`locale.setlocale` before using ``'n'``. |
514521
+---------+----------------------------------------------------------+
515522
| None | The same as ``'d'``. |
516523
+---------+----------------------------------------------------------+
@@ -593,10 +600,15 @@ The available presentation types for :class:`float` and
593600
| | ``'E'`` if the number gets too large. The |
594601
| | representations of infinity and NaN are uppercased, too. |
595602
+---------+----------------------------------------------------------+
596-
| ``'n'`` | Number. This is the same as ``'g'``, except that it uses |
603+
| ``'n'`` | .. _n-format-float: |
604+
| | |
605+
| | Number. This is the same as ``'g'``, except that it uses |
597606
| | the current locale setting to insert the appropriate |
598-
| | digit group separators |
599-
| | for the integral part of a number. |
607+
| | digit group separators for the integral part of a |
608+
| | number. Note that the default locale is not the system |
609+
| | locale. Depending on your use case, you may wish to set |
610+
| | :const:`~locale.LC_NUMERIC` with |
611+
| | :func:`locale.setlocale` before using ``'n'``. |
600612
+---------+----------------------------------------------------------+
601613
| ``'%'`` | Percentage. Multiplies the number by 100 and displays |
602614
| | in fixed (``'f'``) format, followed by a percent sign. |

0 commit comments

Comments
 (0)