473,603 Members | 2,664 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2725
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.setlocal e(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.setlocal e(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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3882
by: Adrian Parker | last post by:
I have a server app which is sent a date in the local format of the client machine. I've no control over the client app at all, so have to code at the server end to cope with any problems. The server is in the US, so any dates need to be in US format before they will convert using strtotime() Here is what i'm doing at the moment.. // need to convert date to use USA mm/dd/yyyy format on server $split = explode(",",$_SERVER);
3
3241
by: Ksenia Marasanova | last post by:
Hi, I have some problems with locale module. On my workstation, changing locale doesn't have effect: Python 2.3 (#1, Sep 13 2003, 00:49:11) on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import locale >>> locale.setlocale(locale.LC_ALL, 'nl_NL')
10
2159
by: Timothy Smith | last post by:
hi there i need to set my locale so that when i output a number it's formatted with thousands grouped. the problem i've found is there doesn't seem to be very good cross platform support for locales, even between unix's it's horrid.
4
7834
by: Roger Leigh | last post by:
Hello, I'm writing a fixed-precision floating point class, based on the ideas in the example fixed_pt class in the "Practical C++ Programming" book by Steve Oualline (O' Reilly). This uses a long int to store the value, and the precision (number of decimal points) is variable (it's a templated class): template <size_t _decimal_places = 4> class FixedFloat {
14
9802
by: wane | last post by:
Hello, I have heard that one should avoid using float and double in monetary calculation because of the lack of preciseness. What is a good alternative? Thanks
2
3961
by: Mike Conmackie | last post by:
Greetings, Is there any way to force strftime() to ignore locale settings when formatting the resulting string? I have a requirement to create a specific date-time string format in UTC. gmtime() will populate a struct tm with the correct values but strftime() always assumes that the values are in local time. I could manually adjust the struct tm values so that strftime() would generate the desired string but it gets really ugly when...
6
2987
by: Troels Arvin | last post by:
Hello, In the init-script contained in the RPMs downloadable from the PostgreSQL site (I checked the one for Fedora), an explicit locale is set before running initdb. - And the explicit locale is not "C". This means that a PostgreSQL installation will not use indexes for LIKE queries (I just ran into this). See http://www.postgresql.org/docs/faqs/FAQ.html#4.8
1
1147
by: tkpmep | last post by:
To pretty up some numbers stored as strings, I used locale to format them with commas. I then found the following error: 'English_United States.1252' Traceback (most recent call last): File "<pyshell#28>", line 1, in <module> locale.format('%d', float('2244012500.0000'), grouping = True)
0
1524
by: Roman Bertle | last post by:
Hello, I try to format monetary values using the locale module, python2.5: Python 2.5.2a0 (r251:54863, Jan 3 2008, 17:59:56) on linux2 Type "help", "copyright", "credits" or "license" for more information. 'de_AT.utf8' {'mon_decimal_point': ',', 'int_frac_digits': 2, 'p_sep_by_space': 1, 'frac_digits': 2, 'thousands_sep': '', 'n_sign_posn': 1,
0
7996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8415
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8060
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8273
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6735
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5878
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5441
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3903
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
1259
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.