Skip to content

Commit f57111d

Browse files
authored
Add references to locale module for locale-aware number formatting
1 parent 4109a9c commit f57111d

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

Doc/library/string.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,9 @@ of a number respectively. It can be one of the following:
469469
| | this option is not supported. |
470470
+---------+----------------------------------------------------------+
471471

472-
For a locale aware separator, use the ``'n'`` presentation type instead.
472+
For a locale-aware separator, use the ``'n'`` presentation type instead. Note
473+
that the locale setting for numeric values must first be set using the
474+
:mod:`locale` module, *e.g.,* ``locale.setlocale(locale.LC_NUMERIC, 'en_US')``.
473475

474476
.. versionchanged:: 3.1
475477
Added the ``','`` option (see also :pep:`378`).
@@ -517,7 +519,8 @@ The available integer presentation types are:
517519
+---------+----------------------------------------------------------+
518520
| ``'n'`` | Number. This is the same as ``'d'``, except that it uses |
519521
| | the current locale setting to insert the appropriate |
520-
| | digit group separators. |
522+
| | digit group separators, provided that the locale has |
523+
| | been properly set (see the :mod:`locale` module). |
521524
+---------+----------------------------------------------------------+
522525
| None | The same as ``'d'``. |
523526
+---------+----------------------------------------------------------+
@@ -599,8 +602,9 @@ The available presentation types for :class:`float` and
599602
+---------+----------------------------------------------------------+
600603
| ``'n'`` | Number. This is the same as ``'g'``, except that it uses |
601604
| | the current locale setting to insert the appropriate |
602-
| | digit group separators |
603-
| | for the integral part of a number. |
605+
| | digit group separators for the integral part of a |
606+
| | number, provided that the locale has been properly set |
607+
| | (see the :mod:`locale` module). |
604608
+---------+----------------------------------------------------------+
605609
| ``'%'`` | Percentage. Multiplies the number by 100 and displays |
606610
| | in fixed (``'f'``) format, followed by a percent sign. |

0 commit comments

Comments
 (0)