prePEP: Decimal data type
Mel Wilson
mwilson at the-wire.com
Sat Nov 1 12:23:41 EST 2003
In article <vq7ogq9t7t9017 at news.supernews.com>,
"John Roth" <newsgroups at jhrothjr.com> wrote:
>As I said in the response to Alex, division is the one place where
>fixed decimal gets into trouble. To repeat what I said to him,
>I'd eliminate the division operators completely, and replace them
>with a div(dividend, divisor, [resultplaces], [roundingpolicy])
>operator.
I don't really like this, because it makes Decimals look
unlike numbers.
But if I had to live with it, I'd probably wind up coding
things like
factor1 = Decimal ('0d.333') # 1/3 to 3 places
sales_tax_rate = Decimal (7, -2) # .07
(where '0d.333' is something I just cooked up as a
compromise between avoiding Decimal+string arithmetic and
accepting the fact that a series of digits is the best way
to express a decimal number.)
Then the standard multiply would do what I wanted, and I
would have said, in building the factors, exactly what I
thought I was doing.
I admit that the implementation I'm playing with doesn't
implement __div__ or __truediv__ yet .. because I can't
figure out the right way.
Regards. Mel.
More information about the Python-list
mailing list