[Python-Dev] Mixing float and Decimal -- thread reboot
Guido van Rossum
guido at python.org
Mon Mar 22 20:52:24 CET 2010
On Mon, Mar 22, 2010 at 11:36 AM, Raymond Hettinger
<raymond.hettinger at gmail.com> wrote:
> One other thought.
>
> The Decimal constructor should now accept floats as a possible input type.
> Formerly, we separated that out to Decimal.from_float() because
> decimals weren't interoperable with floats.
Not sure this follows; Fraction(1.1) raises an exception, you have to
use Fraction.from_float().
> This will put decimal and float back on equal footing so that we have both:
> float(some_decimal) # coerce to binary float
> and
> Decimal(some_float) # coerce to decimal float
If you really want this I won't stop you.
> That will also save us from odd idioms like:
>
> d = some_float + Decimal(0) # coerce to decimal then apply context rounding
Although this isn't too bad:
d = Decimal.from_float(some_float)
> This also matches the behavior of other constructors:
> int(some_float)
> or
> int(some_decimal)
> or
> str(some_float)
> or
> str(some_decimal)
True, I don't care strongly.
--
--Guido van Rossum (python.org/~guido)
More information about the Python-Dev
mailing list