prePEP: Money data type

Ian Bicking ianb at colorstudy.com
Sat Oct 18 11:26:07 EDT 2003


On Friday, October 17, 2003, at 06:39 PM, John Roth wrote:
> 1. I've seen lots of strange rounding policies in
> various nooks and crannies. Is there any way of
> specifying a rounding policy that would be used
> and inherited by the result money object?

Does the rounding policy belong to the money, or to the context in 
which the money is used?  I would expect it belongs to the context, 
which would imply the policy should be specified by method name or an 
argument to a method.

> 4. Repr should round trip. That's basic
> Python. This means that repr() should
> return something that the money()
> constructor understands regardless of
> the current locale setting.
> Making it human readable is the responsibility
> of either str(), the % operator or a hypothetical
> .printf() method.

No, the only places where repr() round trips is for Python literals.  
If there was a literal representation for a money object, then yes use 
that, otherwise the result of repr should be programmer readable and 
helpful.

> 6. On operators. What happens to precision
> on multiplication and division?

My impression of accounting rules (of which I'm not highly informed) is 
that numbers are always presumed to be completely accurate, by dictate 
if not circumstance.  You settle accounts by transferring money -- you 
can't transfer ranges of money or fuzzy amounts of money.  It's better 
to be arbitrary than imprecise in this instance.

This article lays out some common requirements for money:

   http://www.martinfowler.com/ap2/quantity.html

--
Ian Bicking | ianb at colorstudy.com | http://blog.ianbicking.org






More information about the Python-list mailing list