prePEP: Money data type

Batista, Facundo FBatista at uniFON.com.ar
Mon Oct 20 14:49:49 EDT 2003


#- I've made a few edits for spelling and grammar, but I
#- haven't cleaned up everything, and I haven't made
#- any substantive changes to the text. Do with it what
#- you will.

Thank you very much!


#- 2. Money objects are presumably immutable, the same
#- as all other numeric objects. I've edited item 4 to
#- presume this.

I added a item #13 that explicitly ask for it to be immutable.


#- 3. I haven't looked at Tim Peter's fixed point
#- module, so I don't know how he handled this.
#- Formatting characters should come from the
#- current locale, or else should be supplied by
#- an extended format method. In fact, I'd make
#- this a requirement: there should be a formatting
#- method that would handle the most common
#- commercial formatting requirements, including
#- zero and asterisk fill, floating and fixed currency
#- symbol, and blanking the entire output field
#- when it is zero. Also trailing minus sign, and
#- so forth.

There're so many ways, that maybe the best solution is to just let everybody
to subclass Money and redefine __str__. The problem is that decimalSeparator
and thousandSeparator are important to parse the string in the constructor.


#- 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.

You mean that to a given m=Money(...),  m == eval(repr(m)) ?


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

The operation itself gets done with the better precision it can be made, and
then rounded.

For example:

>>> m = Money(5, 2)
>>> print m/2
$2.50
>>> print m/3
$1.67



.	Facundo





. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
ADVERTENCIA  

La información contenida en este mensaje y cualquier archivo anexo al mismo,
son para uso exclusivo del destinatario y pueden contener información
confidencial o propietaria, cuya divulgación es sancionada por la ley. 

Si Ud. No es uno de los destinatarios consignados o la persona responsable
de hacer llegar este mensaje a los destinatarios consignados, no está
autorizado a divulgar, copiar, distribuir o retener información (o parte de
ella) contenida en este mensaje. Por favor notifíquenos respondiendo al
remitente, borre el mensaje original y borre las copias (impresas o grabadas
en cualquier medio magnético) que pueda haber realizado del mismo. 

Todas las opiniones contenidas en este mail son propias del autor del
mensaje y no necesariamente coinciden con las de Telefónica Comunicaciones
Personales S.A. o alguna empresa asociada. 

Los mensajes electrónicos pueden ser alterados, motivo por el cual
Telefónica Comunicaciones Personales S.A. no aceptará ninguna obligación
cualquiera sea el resultante de este mensaje. 

Muchas Gracias.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20031020/89b9a4a2/attachment.html>


More information about the Python-list mailing list