]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-134887: Add references to `locale` module for locale-aware number formatting refer...
authorStefanie Molin <24376333+stefmolin@users.noreply.github.com>
Tue, 19 May 2026 21:10:39 +0000 (17:10 -0400)
committerGitHub <noreply@github.com>
Tue, 19 May 2026 21:10:39 +0000 (23:10 +0200)
Doc/library/string.rst

index 08ccdfa3f454f8d61e4cb41ea0e8894c94dec0c0..be968a3c53d84305d25b266abc0e217c1657c604 100644 (file)
@@ -472,7 +472,9 @@ 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'``
+:ref:`float presentation type <n-format-float>` or
+:ref:`integer presentation type <n-format-integer>` instead.
 
 .. versionchanged:: 3.1
    Added the ``','`` option (see also :pep:`378`).
@@ -518,9 +520,14 @@ The available integer presentation types are:
    |         | In case ``'#'`` is specified, the prefix ``'0x'`` will   |
    |         | be upper-cased to ``'0X'`` as well.                      |
    +---------+----------------------------------------------------------+
-   | ``'n'`` | Number. This is the same as ``'d'``, except that it uses |
+   | ``'n'`` | .. _n-format-integer:                                    |
+   |         |                                                          |
+   |         | 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. Depending on your use case, you   |
+   |         | may wish to set :const:`~locale.LC_NUMERIC` with         |
+   |         | :func:`locale.setlocale` before using ``'n'``.           |
    +---------+----------------------------------------------------------+
    | None    | The same as ``'d'``.                                     |
    +---------+----------------------------------------------------------+
@@ -603,10 +610,15 @@ The available presentation types for :class:`float` and
    |         | ``'E'`` if the number gets too large. The                |
    |         | representations of infinity and NaN are uppercased, too. |
    +---------+----------------------------------------------------------+
-   | ``'n'`` | Number. This is the same as ``'g'``, except that it uses |
+   | ``'n'`` | .. _n-format-float:                                      |
+   |         |                                                          |
+   |         | 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. Depending on your use case, you may wish to set  |
+   |         | :const:`~locale.LC_NUMERIC` with                         |
+   |         | :func:`locale.setlocale` before using ``'n'``.           |
    +---------+----------------------------------------------------------+
    | ``'%'`` | Percentage. Multiplies the number by 100 and displays    |
    |         | in fixed (``'f'``) format, followed by a percent sign.   |