diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2024-10-14 08:24:01 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-14 08:24:01 (GMT) |
commit | 5217328f93f599755bd70418952392c54f705a71 (patch) | |
tree | 87e238d2b2cdd326b396db73e582c535ef623836 /Doc/library | |
parent | 4b358ee647809019813f106eb901f466a3846d98 (diff) | |
download | cpython-5217328f93f599755bd70418952392c54f705a71.zip cpython-5217328f93f599755bd70418952392c54f705a71.tar.gz cpython-5217328f93f599755bd70418952392c54f705a71.tar.bz2 |
gh-121798: Add class method Decimal.from_number() (GH-121801)
It is an alternate constructor which only accepts a single numeric argument.
Unlike to Decimal.from_float() it accepts also Decimal.
Unlike to the standard constructor, it does not accept strings and tuples.
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/decimal.rst | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst index 916f17c..c9a3e44 100644 --- a/Doc/library/decimal.rst +++ b/Doc/library/decimal.rst @@ -598,6 +598,23 @@ Decimal objects .. versionadded:: 3.1 + .. classmethod:: from_number(number) + + Alternative constructor that only accepts instances of + :class:`float`, :class:`int` or :class:`Decimal`, but not strings + or tuples. + + .. doctest:: + + >>> Decimal.from_number(314) + Decimal('314') + >>> Decimal.from_number(0.1) + Decimal('0.1000000000000000055511151231257827021181583404541015625') + >>> Decimal.from_number(Decimal('3.14')) + Decimal('3.14') + + .. versionadded:: 3.14 + .. method:: fma(other, third, context=None) Fused multiply-add. Return self*other+third with no rounding of the |