This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Documentation error in Decimal module
Type: Stage:
Components: Documentation Versions: Python 3.2, Python 3.3
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: georg.brandl, holdenweb, rhettinger, skrah
Priority: normal Keywords:

Created on 2011-07-17 18:30 by holdenweb, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg140531 - (view) Author: Steve Holden (holdenweb) * (Python committer) Date: 2011-07-17 18:30
We see in the "Quick-Start Tutorial" (py3k section 8.4.1) the following example:

>>> Decimal(3.14)
Decimal('3.140000000000000124344978758017532527446746826171875')

In actua; fact one would expect an exception from that code, which should perhaps instead read

>>> Decimal.from_float(3.14)
Decimal('3.140000000000000124344978758017532527446746826171875')

This class method is the recommended way to convert floats to decimal when necessary.
msg140532 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2011-07-17 18:50
Behavior for mixed operations varies greatly between Python versions.

The first table over here lists the differences and should be valid
for decimal.py:

http://www.bytereef.org/mpdecimal/doc/cdecimal/index.html#floatoperation-signal


As an extension, cdecimal has the FloatOperation signal, which
enforces stricter semantics. The second table on that page lists
the behavior if the signal is enabled.
msg140535 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2011-07-17 19:07
The example is correct and runs as expected:

>>> Decimal(3.14)
Decimal('3.140000000000000124344978758017532527446746826171875')

Per the Whatsnew3.2 document:
'''
The decimal.Decimal constructor now accepts float objects directly so there in no longer a need to use the from_float() method (issue 8257).
'''
msg140536 - (view) Author: Steve Holden (holdenweb) * (Python committer) Date: 2011-07-17 19:23
Sorry about that. I was using 3.1, as you will have gathered.
History
Date User Action Args
2022-04-11 14:57:19adminsetgithub: 56789
2011-07-17 19:23:09holdenwebsetstatus: open -> closed

messages: + msg140536
2011-07-17 19:07:50rhettingersetmessages: + msg140535
2011-07-17 19:04:53rhettingersetassignee: georg.brandl -> rhettinger

nosy: + rhettinger
versions: + Python 3.3, - Python 3.1
2011-07-17 18:50:57skrahsetnosy: + skrah
messages: + msg140532
2011-07-17 18:30:46holdenwebsetcomponents: + Documentation
2011-07-17 18:30:01holdenwebcreate