Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #20116
| References | <eb1973ef-913e-408a-b491-d1449c8434e2@c21g2000yqi.googlegroups.com> <jh1at1$rai$1@dough.gmane.org> <CAMZYqRRQ9MPwV+mCmXmoWc+swNc=Y5LrMzQPSr4dgC-TtiqErw@mail.gmail.com> <jh1d2h$9eb$2@dough.gmane.org> |
|---|---|
| Date | 2012-02-09 14:12 -0800 |
| Subject | Re: Formate a number with commas |
| From | Chris Rebert <clp2@rebertia.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5617.1328825558.27778.python-list@python.org> (permalink) |
On Thu, Feb 9, 2012 at 1:16 PM, Peter Otten <__peter__@web.de> wrote:
> Chris Rebert wrote:
>> On Thu, Feb 9, 2012 at 12:39 PM, Peter Otten <__peter__@web.de> wrote:
>>>>>> import locale
>>>>>> locale.setlocale(locale.LC_ALL, "")
>>> 'de_DE.UTF-8'
>>>>>> "{:n}".format(1234) # locale-aware
>>> '1.234'
>>>>>> "{:,d}".format(1234) # always a comma
>>> '1,234'
>>
>> The latter requires Python 3.1+ and is courtesy PEP 378
>> (http://www.python.org/dev/peps/pep-0378/ ).
>
> I actually ran the above session in 2.7, so that should do, too.
>
> http://docs.python.org/whatsnew/2.7.html#pep-378-format-specifier-for-
> thousands-separator
Argh. The 2.7 docs say it was added in 2.7, but the 3.3a0 docs say it
was added in 3.1 (Guido's backporting time machine messes with
"causality").
Both statements are completely technically correct, but misleading
when not taken together.
Cheers,
Chris
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Formate a number with commas noydb <jenn.duerr@gmail.com> - 2012-02-09 12:08 -0800 Re: Formate a number with commas Neil Cerutti <neilc@norwich.edu> - 2012-02-09 20:17 +0000 Re: Formate a number with commas Peter Otten <__peter__@web.de> - 2012-02-09 21:39 +0100 Re: Formate a number with commas Chris Rebert <clp2@rebertia.com> - 2012-02-09 12:51 -0800 Re: Formate a number with commas Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2012-02-09 22:13 +0100 Re: Formate a number with commas Peter Otten <__peter__@web.de> - 2012-02-09 22:16 +0100 Re: Formate a number with commas Chris Rebert <clp2@rebertia.com> - 2012-02-09 14:12 -0800 Re: Formate a number with commas John Posner <jjposner@optimum.net> - 2012-02-09 17:57 -0500 Re: Formate a number with commas Terry Reedy <tjreedy@udel.edu> - 2012-02-09 22:06 -0500
csiph-web