[issue4796] Decimal to receive from_float method
Raymond Hettinger
report at bugs.python.org
Fri Jan 2 21:44:15 CET 2009
Raymond Hettinger <rhettinger at users.sourceforge.net> added the comment:
> once you've converted your float to Decimal it's trivial
> to round it to whatever precision you feel like, so #2
> seems unnecessary to me.
Agree with Mark on how to control rounding. The DecimalWay(tm) is that
used by Context.create_decimal(). A second argument is problematic for
two reasons. First, it demands that some rounding take place but
doesn't let you control the rounding method or signal an Inexact
conversion -- you need a context for that. Second, the API for decimal
is already somewhat complex and we don't want to make it worse by
introducing a new variant with a second argument that has no parallel
elsewhere in the API.
Also agree with Mark regarding Decimal.from_float() which needs to be
lossless and exact. It parallels fractions.from_float() which does the
same thing for rationals.
The DecimalWay(tm) is to have Decimal constructors be exact and to use
Context based constructors when rounding is desired.
I'll submit a patch to this effect (unless someone beats me to it).
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4796>
_______________________________________
More information about the Python-bugs-list
mailing list