[Python-Dev] prePEP: Money data type

Batista, Facundo FBatista at uniFON.com.ar
Mon Oct 20 10:41:23 EDT 2003


#- FWIW, Rogue Wave's Money class lets you specify _either_ rounding
#- approach -- ROUND_PLAIN specifies EU-rules-compliant rounding,
#- ROUND_BANKERS specifies round-to-even, for exactly in-between
#- amounts.  Offhand, it would seem impossible to write an accounting
#- program that respects the law in Europe AND the praxis you mention
#- at the same time, unless you somehow tell it what rule to use.
#- 
#- Sad, and seems weird to go to such trouble for a cent, but 
#- accountants
#- live and die by such minutiae: I think it would not be wise 
#- to ignore them,
#- PARTICULARLY if we name the type so as to make it appear to the
#- uninitiated that it "will do the right thing" regarding 
#- rounding... when there
#- isn't ONE right thing, it depends on locale &c:-(.

Seems to me that the best would be to have two functions (liked the names
roundPlain and roundBankers), and the behaviour to be specified by the user.
But here I found two approaches:

	- By argument: Redefine the sintaxis with Money(value, [precision],
[round]), having a specified default for round.

	- By subclassing: Just make:
		class MyMoney(Money):
			moneyround = roundPlain

The first is better in the way that you use Money directly, but you need to
specify *always* the rounding. In the second way you have to subclass it one
time, but then all the job is done (anyway, maybe you was already
subclassing Money to change it decimalSeparator or something).

Personally, I go for the second choice.

.	Facundo



More information about the Python-Dev mailing list