Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #20108

Re: Formate a number with commas

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.009
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; '>>>>': 0.09; 'locale': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'comma': 0.16; 'pythonic': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'true)': 0.16; 'wrote:': 0.18; '>>>': 0.18; 'from:addr:web.de': 0.23; 'import': 0.27; "i'm": 0.28; "skip:' 10": 0.29; 'print': 0.29; 'subject:number': 0.30; 'skip:l 30': 0.32; 'this.': 0.33; 'header:X-Complaints-To:1': 0.34; 'to:addr:python-list': 0.35; 'skip:" 20': 0.35; 'received:org': 0.36; 'skip:" 10': 0.37; 'subject:with': 0.37; 'some': 0.38; 'format': 0.38; 'to:addr:python.org': 0.40; 'quick': 0.61; 'more': 0.61; 'perpetual': 0.84; 'proper,': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: Formate a number with commas
Date Thu, 09 Feb 2012 21:39 +0100
Organization None
References <eb1973ef-913e-408a-b491-d1449c8434e2@c21g2000yqi.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p5084adf6.dip.t-dialin.net
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5610.1328819948.27778.python-list@python.org> (permalink)
Lines 25
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1328819949 news.xs4all.nl 6857 [2001:888:2000:d::a6]:44952
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:20108

Show key headers only | View raw


noydb wrote:

> How do you format a number to print with commas?
> 
> Some quick searching, i came up with:
> 
>>>> import locale
>>>> locale.setlocale(locale.LC_ALL, "")
>>>> locale.format('%d', 2348721, True)
> '2,348,721'
> 
> 
> I'm a perpetual novice, so just looking for better, slicker, more
> proper, pythonic ways to do this.

>>> 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'


Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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