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


Groups > comp.lang.python > #12008

Re: locale.format without trailing zeros

From Anssi Saari <as@sci.fi>
Newsgroups comp.lang.python
Subject Re: locale.format without trailing zeros
Date 2011-08-22 13:59 +0300
Message-ID <vg339gt7lud.fsf@coffee.modeemi.fi> (permalink)
References <mailman.303.1314005406.27778.python-list@python.org>

Show all headers | View raw


przemolicc@poczta.fm writes:

> Hello,
>
>>>> import locale
>>>> locale.setlocale(locale.LC_ALL, "pl_PL")
> 'pl_PL'
>>>> i=0.20
>>>> j=0.25
>>>> locale.format('%f', i)
> '0,200000'
>>>> locale.format('%f', j)
> '0,250000'
>
> I need to print the numbers in the following format:
> '0,2'	(i)
> '0,25'	(j)
> So the last trailing zeros are not printed.

That would be the %g conversion specifier.

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


Thread

locale.format without trailing zeros przemolicc@poczta.fm - 2011-08-22 10:52 +0200
  Re: locale.format without trailing zeros Peter Otten <__peter__@web.de> - 2011-08-22 11:48 +0200
    Re: locale.format without trailing zeros przemolicc@poczta.fm - 2011-08-22 13:08 +0200
    Re: locale.format without trailing zeros przemolicc@poczta.fm - 2011-08-22 13:29 +0200
      Re: locale.format without trailing zeros Peter Otten <__peter__@web.de> - 2011-08-22 15:01 +0200
  Re: locale.format without trailing zeros Anssi Saari <as@sci.fi> - 2011-08-22 13:59 +0300

csiph-web