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


Groups > comp.lang.python > #109059 > unrolled thread

Re: str(float) python 3 versus 2.7

Started byRobin Becker <robin@reportlab.com>
First post2016-05-24 15:47 +0100
Last post2016-05-24 15:47 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#109059 — Re: str(float) python 3 versus 2.7

FromRobin Becker <robin@reportlab.com>
Date2016-05-24 15:47 +0100
SubjectRe: str(float) python 3 versus 2.7
Message-ID<mailman.55.1464101239.20402.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web