[Tutor] Formatting Numbers as Strings 33000.50 -> 33,000.50 ?

Jethro Cramp jsc_lists@rock-tnsc.com
Thu, 29 Mar 2001 10:49:10 +0800


> The correct command seems to be 'locale.format("%f", f, 1).
>
> The '1' means that grouping is used, i.e. commas every three figures. As
> least, if I read the docs correctly
> (http://www.python.org/doc/current/lib/module-locale.html).

Thank you. That makes a *big* difference

> Did the setlocale(LC_ALL,"us") work? What's the output of
> locale.localeconv()?

Yes. The output is:

>>> locale.setlocale(locale.LC_ALL, "us")
'English_United States.1252'

Interestingly enough though the attempt to set German using "de" didn't
work. But France using "fr" was successful. I guess there are some more
things that I will investigate here.

> The currency symbol is in locale.localeconv()['currency_symbol'],
> apparently. I can't test here and I've never used it, so I'm
> getting it from
> the docs...
>
Thanks. I was hoping there would be a function that given a number would
return a properly formatted string with the currency symbol. This should be
easy enough to right using the paramaters from locale.

Once again Thanks.

Jethro
>