Login or Sign Up
Logging in...
Remember me
Log in
Or
Sign Up
Forgot password or user name?
Log in with
Search in titles only
Search in Python only
Search
Advanced Search
Forums
BYTES
Product Launch
Updates
Developer Toolkit
Today's Posts
Member List
Calendar
Home
Forum
Topic
Python
formatting a string with thousands separators
Collapse
This topic is closed.
X
X
Collapse
Posts
Latest Activity
Photos
Page
of
1
Filter
Time
All Time
Today
Last Week
Last Month
Show
All
Discussions only
Photos only
Videos only
Links only
Polls only
Events only
Filtered by:
Clear All
new posts
Previous
template
Next
SimonPalmer
#1
formatting a string with thousands separators
Sep 7 '08, 04:25 PM
anyone recommend a way of formatting floats with comma separators?
e.g. 500000.00 -500,000.00
Alan G Isaac
#2
Sep 7 '08, 07:25 PM
Re: formatting a string with thousands separators
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
Comment
Post
Cancel
James Mills
#3
Sep 7 '08, 09:55 PM
Re: formatting a string with thousands separators
Hi,
There is a much easier more consistent way:
>>import locale
>>locale.setloc ale(locale.LC_A LL, "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 <alan.isaac@gma il.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
--
429 Too Many Requests
http://mail.python.org/mailman/listinfo/python-list
>
--
--
-- "Problems are solved by method"
Comment
Post
Cancel
Fredrik Lundh
#4
Sep 7 '08, 10:05 PM
Re: formatting a string with thousands separators
James Mills wrote:
There is a much easier more consistent way:
>
>>>import locale
>>>locale.setlo cale(locale.LC_ ALL, "en_AU.UTF-8")
'en_AU.UTF-8'
doesn't work on all Python platforms, though:
>>locale.setloc ale(locale.LC_A LL, "en_AU.UTF-8")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\python25\li b\locale.py", line 478, in setlocale
return _setlocale(cate gory, 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.setloc ale(locale.LC_A LL, os.environ["LANG"])
'sv_SE.UTF-8'
>>locale.format ("%0.2f", 5000000, True)
'5000000,00'
</F>
Comment
Post
Cancel
Previous
template
Next
Working...
Yes
No
OK
OK
Cancel
👍
👎
☕
Comment