Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.087 X-Spam-Evidence: '*H*': 0.85; '*S*': 0.02; ':-)': 0.06; '>>>>': 0.09; 'locale': 0.09; 'trailing': 0.09; 'zeros': 0.09; '0.1)': 0.16; 'mon,': 0.16; 'wrote:': 0.16; '>>>': 0.18; 'header:In-Reply-To:1': 0.22; 'aug': 0.24; 'skip:l 30': 0.24; 'import': 0.28; 'print': 0.29; '+0200,': 0.30; '22,': 0.30; 'format:': 0.30; 'to:addr :python-list': 0.33; 'header:User-Agent:1': 0.34; 'thank': 0.35; 'subject:: ': 0.39; 'to:addr:python.org': 0.39; 'from:no real name:2**0': 0.63; 'charset:iso-8859-2': 0.66; 'subject:without': 0.67; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.71; 'received:pl': 0.84; 'dla': 0.84; 'otten': 0.84; 'subject:skip:l 10': 0.84; 'url:pl': 0.93 Date: Mon, 22 Aug 2011 13:08:40 +0200 From: przemolicc@poczta.fm To: python-list@python.org Subject: Re: locale.format without trailing zeros References: MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) X-Interia-Antivirus: OK X-EMID: 95efc98 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: przemolicc@poczta.fm List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 87 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1314011326 news.xs4all.nl 23894 [2001:888:2000:d::a6]:38278 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12009 On Mon, Aug 22, 2011 at 11:48:46AM +0200, Peter Otten wrote: > przemolicc@poczta.fm wrote: >=20 > >>>> import locale > >>>> locale.setlocale(locale.LC_ALL, "pl_PL") > > 'pl_PL' > >>>> i=3D0.20 > >>>> j=3D0.25 > >>>> locale.format('%f', i) > > '0,200000' > >>>> locale.format('%f', j) > > '0,250000' > >=20 > > I need to print the numbers in the following format: > > '0,2' (i) > > '0,25' (j) > > So the last trailing zeros are not printed. >=20 > >>> print locale.format("%g", 1.23) > 1,23 > >>> print locale.format("%g", 1.2345678) > 1,23457 > >>> print locale.format("%.10g", 1.2345678) > 1,2345678 > >>> print locale.format("%.15g", 0.1) > 0,1 > >>> print locale.format("%.17g", 0.1) > 0,10000000000000001 Thank you very much :-) Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Znajdz samochod idealny dla siebie! Szukaj >> http://linkint.pl/f2a0a