prePEP: Decimal data type

Mel Wilson mwilson at the-wire.com
Sat Nov 8 10:49:10 EST 2003


In article <mailman.486.1068133439.702.python-list at python.org>,
"Tim Peters" <tim.one at comcast.net> wrote:
>    The conversion of prices into euros will require the use of a six-
>    significant-digit conversion rate (six digits disregarding initial
>zeros)
>    which should not be rounded or truncated. This rate will be irrevocably
>    fixed on 1 January 1999 and defined in the form of one euro expressed in
>    national currencies.
>
>So that part mandates a *floating* point input (not meaning binary floating
>point, but "6 digits disregarding initial zeros" is the essence of floating
>point -- the total number of digits isn't fixed, nor is the # of digits
>after the decimal point fixed, just the # of *significant* digits).
>
>    To convert from national currencies to the euro, one has to divide by
>    the conversion rate.  To convert from the euro to the national currency,
>    one has to multiply by the conversion rate.  The use of inverse rates is
>    forbidden.
>
>Neutral.
>
>    To convert from one national currency to another, amounts must be first
>    converted into euros and then into the second national currency.  The
>    euro amount must be rounded to three decimal places.  The national
>    currency should then be rounded to two decimals.
>
>So no single fixed-point discipline can suffice:  in one direction they want
>rounding to 3 digits after the decimal point, in the other to 2 digits, and
>one of the inputs is a floating-point value with no fixed number of digits
>after the decimal point.

   The toy Decimal I'm playing with has a class variable
specifying number of digits to the right of the decimal
point, and this gets used on calls to rounding method(s).
By deriving Euros and Dollars from the Decimal class with
the right digit specifications and calling for rounding at
the right time I might be able to do that.

        Regards.        Mel.




More information about the Python-list mailing list