locale doesn' format

E

Egon Frerich

-----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-----
 
Ð

Дамјан ГеоргиевÑки

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

seems to work here

import decimal, locale
locale.setlocale(locale.LC_ALL, 'mk_MK.UTF-8') 'mk_MK.UTF-8'
locale.localeconv()['grouping'] [3, 3, 0]
locale.localeconv()['thousands_sep'] ' '
locale.localeconv()['decimal_point'] ','
locale.format('%f', 1034.56,True) '1 034,560000'
locale.format('%d', 1034.56,True)
'1 034'



ps.
you can copy/paste the above in .txt file and then run/test it with:
python -m doctest -v check.txt
 

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,780
Messages
2,569,611
Members
45,277
Latest member
VytoKetoReview

Latest Threads

Top