prePEP: Money data type
Batista, Facundo
FBatista at uniFON.com.ar
Mon Oct 20 17:05:35 EDT 2003
More information about the Python-list mailing list
Mon Oct 20 17:05:35 EDT 2003
- Previous message (by thread): prePEP: Money data type
- Next message (by thread): prePEP: Money data type
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Alex Martelli wrote: #- > The problem is that decimalSeparator and thousandSeparator #- are important #- > to parse the string in the constructor (if I need str() to #- give me a ',' #- > as decimal point, I also need to supply a ',' as decimal #- point to the #- > constructor). #- #- Hmmm, I see your point. But, in general, parsing '1.000' would be #- ambiguous -- is it one thousand with '.' as the thousandSeparator or #- one in a currency which requires three decimal digits? Dependes of the values of thousandSeparator and decimalSeparator. If you overload them: thousandSeparator = '.' decimalSeparator = '.' the behaviour is unpredictable (should I generate an exception or something?) #- See? After I called setlocale to set it to the user locale (rather #- than the neutral 'C' locale), 'en_US' in my case, I got lot of info #- in the dict that locale.localeconv() returns: money decimal point is #- '.', fractional-parts-digits are 2 for both base and #- internationalized #- formatting, thousands separator is comma for both ordinary and money #- amounts, the currency symbol is '$' in base use but 'USD' for fully #- internationalized used, etc, etc. ... #- The base class Money seem to need just a few of these to be able to #- parse strings (I would not use them for default output with either #- repr or str, although maybe a non-special method such as 'format' #- MIGHT, for the user's convenience, emit a string formatted by such #- guidelines -- I'm neutral, say +0, on the latter). I was using to parse the input and to build the output, the elements thousandSeparator, decimalSeparator and currencySymbol. This can be very easily overloaded, but the default was MY taste. Seems a lot better to make the default based in locale. Why doesn't like to you to >>> m = Money(23.3, 2) >>> print m $23.30 ? . Facundo
- Previous message (by thread): prePEP: Money data type
- Next message (by thread): prePEP: Money data type
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list