locale doesn' format

Egon Frerich egon.frerich at nord-com.net
Mon Jul 20 17:07:38 EDT 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I want to format values to the german form eg. 1.034,56 but
locale.format() doesn't work for me.

Here is a little test program:

import decimal, locale

print locale.getdefaultlocale()
print locale.localeconv()
locale.setlocale(locale.LC_ALL, ('de_DE', 'UTF-8'))
print locale.localeconv()
k = decimal.Decimal('1034.56')
#k = 1034.56
print 'k', k, type(k)
k1 = locale.format_string('%12s',k,True)
print 'k1', k1, type(k1)
k1a = locale.format('%12s',k,True,True)
print 'k1a', k1a, type(k1a)
k2 = unicode(k1)
print 'k2',k2,type(k2)
print k1.find(',')
print k1a.find(',')
print k2.find(',')
ab = locale.localeconv()['decimal_point']
print 'ab', ab
print locale.localeconv()['decimal_point'].find(',')
print locale.localeconv()['mon_decimal_point'].find(',')
ac = locale.localeconv()['mon_decimal_point']
print 'ac', ac, len(ac)
print locale.localeconv()

k1, k1a, k2 are printed as 1034.56

Egon

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFKZNyaZRiDo9Iq4qIRAuqhAKCW3x7iDbrxUDp3M/qHabwbw92osQCgi6N2
mmgb54LACmrd/Wi4BRi2iZo=
=psal
-----END PGP SIGNATURE-----



More information about the Python-list mailing list