Changing the decimal separator to a comma

A

andyj

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):
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):
' 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
 
J

Jeff Epler

Nothing changes the way that %-formatting works.

However, after calling locale.setlocale, locale.format should give you a
proper localized number:
' 1.234,57'

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)

iD8DBQFBNIsKJd01MZaTXX0RAt/dAJ9/DVy0c/PFCOq/97B9/t8wIoYcHgCfX0SG
WHwyBqiFCtw78xp3lzIlMe0=
=6ysk
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top