Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.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.113 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.79; '*S*': 0.02; '>>>>': 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; '(the': 0.28; '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; 'but': 0.37; '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; 'strange': 0.68; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.71; 'received:pl': 0.84; 'otten': 0.84; 'subject:skip:l 10': 0.84; 'url:pl': 0.93 Date: Mon, 22 Aug 2011 13:29:58 +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: 351efc98 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: 91 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1314012601 news.xs4all.nl 23850 [2001:888:2000:d::a6]:52786 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12011 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 How about this format: ',1' (the local zero is also not printed) (I know this is strange but I need compatibility with local requirements) Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Najwieksza baza najtanszych ofert mieszkaniowych http://linkint.pl/f2a0e