473,508 Members | 2,370 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

formatting a string with thousands separators

anyone recommend a way of formatting floats with comma separators?

e.g. 500000.00 -500,000.00
Sep 7 '08 #1
3 4012
On 9/7/2008 12:22 PM SimonPalmer apparently wrote:
anyone recommend a way of formatting floats with comma separators?

http://code.activestate.com/recipes/498181/

Alan Isaac
Sep 7 '08 #2
Hi,

There is a much easier more consistent way:
>>import locale
locale.setlocale(locale.LC_ALL, "en_AU.UTF-8")
'en_AU.UTF-8'
>>locale.format("%0.2f", 5000000, True)
'5,000,000.00'
>>>
cheers
James

On Mon, Sep 8, 2008 at 5:24 AM, Alan G Isaac <al********@gmail.comwrote:
On 9/7/2008 12:22 PM SimonPalmer apparently wrote:
>>
anyone recommend a way of formatting floats with comma separators?


http://code.activestate.com/recipes/498181/

Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list


--
--
-- "Problems are solved by method"
Sep 7 '08 #3
James Mills wrote:
There is a much easier more consistent way:
>>>import locale
locale.setlocale(locale.LC_ALL, "en_AU.UTF-8")
'en_AU.UTF-8'
doesn't work on all Python platforms, though:
>>locale.setlocale(locale.LC_ALL, "en_AU.UTF-8")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\python25\lib\locale.py", line 478, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting

and is likely to give you somewhat unpredictable output if you use the
machine's actual locale:
>>import os
locale.setlocale(locale.LC_ALL, os.environ["LANG"])
'sv_SE.UTF-8'
>>locale.format("%0.2f", 5000000, True)
'5000000,00'

</F>

Sep 7 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
3464
by: Pascal | last post by:
Hello, I've a float number 123456789.01 and, I'de like to format it like this "123 456 789.01". Is this possible with % character?
7
745
by: Chad Z. Hower aka Kudzu | last post by:
I have a typed dataset that is on a WinForm and I have labels that have their text properties bound to fields in a data table. The values are of type decimal. When I dispaly them in the label, I...
2
1221
by: james | last post by:
Hi Im having a problem getting a number to display correctly. The number is the result of a calculation and I am then using formatnumber to remove any decimals. The number displays as...
16
25850
by: Douglas | last post by:
Gday, How would I format a number so that: TheValue = 32500 Displays in the TextBox as: $32,500.00
22
1754
by: KsAdmin | last post by:
I have a question which has had me stumped for a few days now. I have a form that I add the values of fields together and display the total in a total field. I have the calculations working...
4
6869
by: | last post by:
I have about 20 MsgBox occurance in by program, which I use to inform the user of the progress of the program, or ask confirmation of an action, or simply to act separators to various parts of the...
0
988
by: STP.NET | last post by:
Hello, Is there a way to configure Visual Studio 2005 to reformat the C# source code automatically when a file opens? I worked with several dozens of C# developers at work, open-source...
0
1275
by: bigbrorpi | last post by:
Hi Is it possible to set global number formatting for an application? I need to have all numbers displayed with thousands separators and that's not currently the case. My desktop location...
10
26878
by: Dave griffiths | last post by:
Hi all Using VB2005 on Vista with a Norwegian locale setup. The test program has 3 textboxes the sum held in txt3. Using the code below, txt2 conversion causes an error when it is left empty....
0
7224
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,...
0
7379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7493
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...
0
4706
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...
0
3192
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...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
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...

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.