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.

Author steven.daprano
Recipients steven.daprano
Date 2008-12-31.22:59:17
SpamBayes Score 0.00039794555
Marked as misclassified No
Message-id <1230764359.55.0.955763939043.issue4796@psf.upfronthosting.co.za>
In-reply-to
Content
In the PEP for Decimal, it was discussed that the class should have a 
from_float() method for converting from floats, but to leave it out of 
the Python 2.4 version:
http://www.python.org/dev/peps/pep-0327/#from-float

Following discussions with Mark Dickinson, I would like to request 
that this now be implemented.

The suggested API is:
Decimal.from_float(floatNumber, [decimal_places])

At the risk of derailing the request, I wonder whether it is better to 
give a context rather than a number of decimal places?

Pro: better control over conversion, as you can specify rounding 
method as well as number of decimal places.

Con: more difficult for newbies to understand.

Semi-pro: float to decimal conversions are inherently tricky, perhaps 
we should be discouraging newbies from blindly calling from_float() 
and make the (hypothetical) context argument mandatory rather than 
optional?
History
Date User Action Args
2008-12-31 22:59:19steven.dapranosetrecipients: + steven.daprano
2008-12-31 22:59:19steven.dapranosetmessageid: <1230764359.55.0.955763939043.issue4796@psf.upfronthosting.co.za>
2008-12-31 22:59:18steven.dapranolinkissue4796 messages
2008-12-31 22:59:17steven.dapranocreate