[Python-Dev] Changes to PEP 327: Decimal data type
Batista, Facundo
FBatista at uniFON.com.ar
Mon Mar 15 21:01:12 EST 2004
People:
I'll post a reviewed version of the PEP.
The only differences with the previous one will be the treatmen to float in
both explicit and implicit construction:
------------
In Explicit construction:
You can not call Decimal with a float. Instead you must use a method:
Decimal.fromFloat(). The syntax:
Decimal.fromFloat(floatNumber, positions)
where floatNumber is the float number origin of the construction and
positions is the positions after the decimal point where you apply a
round-half-up
rounding. In this way you can do, for example:
Decimal.fromFloat(1.1, 2): The same that doing Decimal('1.1').
Decimal.fromFloat(1.1, 16): The same that doing
Decimal('1.1000000000000001').
Decimal.fromFloat(1.1): The same that doing
Decimal('110000000000000008881784197001252...e-51').
In Implicit construction:
Raise TypeError. You can not mix Decimal and float.
------------
If you're ok, I'll post this.
Thank you!
. Facundo
More information about the Python-Dev
mailing list