-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
gh-142108: Document Decimal formatting behavior differences #142117
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
Changes from all commits
874fc1c
cae9245
69ad04d
d38b637
b71c072
1199df7
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 |
|---|---|---|
|
|
@@ -629,6 +629,20 @@ | |
| of the :func:`round` builtin. For :class:`~decimal.Decimal`, the rounding | ||
| mode of the current :ref:`context <decimal-context>` will be used. | ||
|
|
||
|
|
||
| .. note:: | ||
|
|
||
| The :class:`~decimal.Decimal` type has special formatting behavior: | ||
|
|
||
| * When using ``__format__`` (f-strings, ``format()``, ``str.format()``), | ||
| Decimal formats with maximum precision only when precision is **omitted** | ||
|
Comment on lines
+637
to
+638
Contributor
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 is already documented, please revert. Also, the whole section of documentation is about string formatting, it's pointless to say that you are using |
||
| in ``f``, ``e``, or ``g`` format types. If precision is explicitly specified, | ||
| it is respected. | ||
|
|
||
| * When using ``%`` formatting (old-style string formatting with the ``%`` operator), | ||
| Decimal values are first converted to :class:`float`, which may result in | ||
|
Comment on lines
+642
to
+643
Contributor
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.
|
||
| precision loss. | ||
|
|
||
| The available presentation types for :class:`complex` are the same as those for | ||
| :class:`float` (``'%'`` is not allowed). Both the real and imaginary components | ||
| of a complex number are formatted as floating-point numbers, according to the | ||
|
|
||
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.
Changes in Doc/c-api/ are not related to this pr, please revert.