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


Groups > comp.lang.python > #109059

Re: str(float) python 3 versus 2.7

From Robin Becker <robin@reportlab.com>
Newsgroups comp.lang.python
Subject Re: str(float) python 3 versus 2.7
Date 2016-05-24 15:47 +0100
Message-ID <mailman.55.1464101239.20402.python-list@python.org> (permalink)
References <7c1af35c-1ac7-96c7-3cba-ab9c8e542d8e@chamonix.reportlab.co.uk> <CALwzidko0E8Pq5158_+G1ufWZtFroC9dsaksusF55fSKW5RWfQ@mail.gmail.com> <38b36519-a231-6d76-bc5e-0e6d5f81808d@chamonix.reportlab.co.uk>

Show all headers | View raw


On 23/05/2016 18:05, Ian Kelly wrote:
> On Mon, May 23, 2016 at 10:39 AM, Robin Becker <robin@reportlab.com> wrote:
.........
>
> If you want to show the float in a less noisy format, you can
> explicitly format it using the 'g' or 'n' presentation type, which
> essentially round to a given precision and strip off trailing zeros:
>
>>>> >>> '{:g}'.format(3*0.2)
> '0.6'
thanks; looking in 2.7 source I believe that the old float.__str__ behaved like 
'%.12g' formatting. I can't imagine why people thought this was a 'good' idea 
though.
-- 
Robin Becker

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


Thread

Re: str(float) python 3 versus 2.7 Robin Becker <robin@reportlab.com> - 2016-05-24 15:47 +0100

csiph-web