prePEP: Decimal data type

Aahz aahz at pythoncraft.com
Thu Nov 6 13:07:24 EST 2003


In article <mailman.446.1067979925.702.python-list at python.org>,
Batista, Facundo <FBatista at uniFON.com.ar> wrote:
>Aahz wrote:
>
>#- >When passing floating point to the constructor, what should happen?
>#- >
>#- >    j. ``Decimal(1.1) == Decimal('1.1')``
>#- >    k. ``Decimal(1.1) ==
>#- >Decimal('110000000000000008881784197001252...e-51')``
>#- 
>#- That's tough.  I'm inclined toward requiring an explicit conversion
>#- through a function call that isn't the Decimal constructor, 
>#- but ease of
>#- use is also a factor.
>
>We can have a Decimal.fromFloat(...), but with behaviour j or k?

k

The user can always apply appropriate rounding.

>#- >2. The value could be of the type:
>#- >
>#- >       - another Decimal
>#- >       - int or long
>#- >       - float
>#- >       - string 
>#- 
>#- Also a tuple of int/longs.
>
>I didn't include that in the prePEP because it seems that the actual
>implementation support this just to dec == Decimal(repr(dec)), for every
>Decimal as dec.
>
>Has any other advantage?

Yes: it means that someone who has numeric values representing a Decimal
does not need to convert them to a string.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"It is easier to optimize correct code than to correct optimized code."
--Bill Harlan




More information about the Python-list mailing list