converting currency using locals

Gabriel Genellina gagsl-py2 at
Thu Apr 19 02:01:27 CEST 2007

En Wed, 18 Apr 2007 15:08:24 -0300, Grzegorz Ślusarek <gregtech at>  

> Hi all. I have situation that I have value that holds price and I must  
> show
> this price using national specification(e.g. thousands_sep). Any idea how
> this can be done under python 2.4.4? I saw that function format from  
> module
> locals can format value with national specification, but this could be  
> done
> only in python 2.5. Any solution for 2.4?
> example what I want achieve:
> value 24500.50
> Hungarian Price 24 500.50
> Romaniam Price 24.500.50
> Thanks for any help
> Gregor

Python 2.4.4 can handle thousands separator and grouping but not  
*specific* settings for monetary values. That is, when  
thousands_sep==mon_thousands_sep and grouping==mon_grouping and  
decimal_point==mon_decimal_point the following code works also for  
monetary values:
(I've checked the 'hu' and 'ro' locales on my system and both have that  

Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on  
Type "help", "copyright", "credits" or "license" for more information.
py> import locale
py> locale.setlocale(locale.LC_ALL, '')
py> help(locale.format)
Help on function format in module locale:

format(f, val, grouping=0)
     Formats a value in the same way that the % formatting would use,
     but takes the current locale into account.
     Grouping is applied if the third parameter is true.

py> locale.format('%.2f', 1234567.1234, True)

Gabriel Genellina

More information about the Python-list mailing list