Changing the decimal separator to a comma
andyj
andrew.jewell at upm-kymmene.com
Tue Aug 31 10:12:59 EDT 2004
I've tried using the locale module to set the locale correctly, but
all I get is "Error: unsupported locale setting".
I'm not actually sure what the proper setting should be; I think it's
"fi" for Finland, but this is what I get when I try (under py 2.2):
>>> locale.setlocale(locale.LC_ALL,"fi")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/python2.2.2/lib/locale.py", line 372, in setlocale
return _setlocale(category, locale)
locale.Error: locale setting not supported
Under 2.3 the call succeeds but makes no difference to the decimal
point (which should be a comma for Finland):
>>> locale.setlocale(locale.LC_ALL,"fi")
'Finnish_Finland.1252'
>>> 0.123
0.123
>>> "%10.2f" % 0.123
' 0.12'
The program I'm working on produces database records using a format
string, and I'm currently manually tracking all the dp's and replacing
them in a loop, just before writing the record to disk, but this is
inefficient and inelegant.
What I'd *like* to be able to do is specify that we want to use commas
for dp's or adjust the locale settings accordingly, then just write
the records directly from the format string...
regards,
-andyj
More information about the Python-list
mailing list