Decimal arithmetic, was Re: Python GUI app to impress the boss?

John Roth johnroth at
Thu Oct 3 14:24:07 CEST 2002

"Tim Peters" < at> wrote in message
news:mailman.1033584066.24607.python-list at
> [Tim]
> >> Then please help Doug do that, including *defining* the
> >> rounding disciplines you think are needed; I was never able
> >> to bully <wink> those out of its users,
> [Chris Gonnerman]
> > I keep hearing this... what is the problem, exactly?
> I think the replies (including two of your own <wink>) spoke more
> to this point than I could.  The rules various commercial apps want
> utterly arbitrary by any rational criterion ("always round up", "round
> over 0.4", "round up over 0.7", "it depends on the *next* digit too",
> but that doesn't mean an arbitrary piece of code satisfies the
> If I were still doing this, I expect I'd invent a way for users to
plug in
> their own "final rounding" function, and explicitly disown
> for guessing what they want.

Exactly. The question is how. I'm leaning to making it a property of the
fixed point number object, but I don't see how that works as far as
literals or combining two fixed point objects with different rounding
would go.

The best prior art I can figure is from COBOL, where most of this
stuff happens today. There, the rounding policy is set by the _result_
picture, which is a concept that simply isn't availible in Python (or
other "modern" languages, for that matter.)

And even there, oddball rounding policies require fixup code because
the language doesn't include anything other than round up if the
is >= .5.

John Roth

More information about the Python-list mailing list