prePEP: Decimal data type
Mel Wilson
mwilson at the-wire.com
Sat Nov 1 08:18:33 EST 2003
In article <mailman.295.1067625441.702.python-list at python.org>,
"Batista, Facundo" <FBatista at uniFON.com.ar> wrote:
>When passing floating point to the constructor, what should happen?
>
> j. ``Decimal(1.1) == Decimal('1.1')``
> k. ``Decimal(1.1) ==
>DecimFl('110000000000000008881784197001252...e-51')``
I've been playing with an implementation, and I'm trying out
def __init__ (value=0, exponent=0, places=None):
...
Under the hood there's a decimal-floating-point implementation,
using long for the radix and integer (or long) for the exponent.
To get 11:
d = Decimal (11)
To get 1.1 exactly:
d = Decimal (11, -1)
To get 1.1 from a float:
f = 1.1
d = Decimal (f, 0, 1) # take float value to 1 decimal place
d = Decimal (1.1) # gets `places` from pre-set context
Regards. Mel.
More information about the Python-list
mailing list