469,951 Members | 2,559 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,951 developers. It's quick & easy.

locale, format monetary values

Hi,

Can I use locale to format monetary values? If yes, how? If no, is there
something I can use?

E.g.,
I have 10000 and I want to get "$10,000".

Thanks,
Ray
Apr 17 '06 #1
2 2597
Rares Vernica wrote:
Hi,

Can I use locale to format monetary values? If yes, how? If no, is there
something I can use?

E.g.,
I have 10000 and I want to get "$10,000".


try something like:
import locale
locale.setlocale(locale.LC_ALL, "en-US") 'English_United States.1252' locale.format("%f", 10000, True) '10,000.000000' locale.format("$%.2f", 10000, True)

'$10,000.00'

bye.

--
deelan
http://www.deelan.com/
http://blog.deelan.com/
Apr 17 '06 #2
That's it. Thanks a lot!

There is no example on the locale.format in the docs so I was confused.

Regards,
Ray

deelan wrote:
Rares Vernica wrote:
Hi,

Can I use locale to format monetary values? If yes, how? If no, is
there something I can use?

E.g.,
I have 10000 and I want to get "$10,000".


try something like:
>>> import locale
>>> locale.setlocale(locale.LC_ALL, "en-US") 'English_United States.1252' >>> locale.format("%f", 10000, True) '10,000.000000' >>> locale.format("$%.2f", 10000, True)

'$10,000.00'

bye.

Apr 19 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Adrian Parker | last post: by
3 posts views Thread by Ksenia Marasanova | last post: by
10 posts views Thread by Timothy Smith | last post: by
4 posts views Thread by Roger Leigh | last post: by
6 posts views Thread by Troels Arvin | last post: by
1 post views Thread by tkpmep | last post: by
reply views Thread by Roman Bertle | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.