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


Groups > comp.lang.python > #109006

str(float) python 3 versus 2.7

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Robin Becker <robin@reportlab.com>
Newsgroups comp.lang.python
Subject str(float) python 3 versus 2.7
Date Mon, 23 May 2016 17:39:28 +0100
Lines 32
Message-ID <mailman.25.1464021580.20402.python-list@python.org> (permalink)
References <7c1af35c-1ac7-96c7-3cba-ab9c8e542d8e@chamonix.reportlab.co.uk>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de gSHYslldf3MDtTq1CDATegDuR0O9X3EFna/YoAwtpR2A==
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'nicely': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'rounding': 0.09; 'subject:2.7': 0.09; 'python': 0.10; '2.7': 0.13; 'subject:python': 0.14; '0.6': 0.16; 'labels,': 0.16; 'naive': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'subject:versus': 0.16; 'string': 0.17; 'figures': 0.18; 'numerical': 0.18; 'all,': 0.20; 'prevent': 0.20; 'object.': 0.22; 'suppose': 0.22; 'leave': 0.23; 'errors': 0.23; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'function': 0.28; 'behaviour': 0.29; 'issues.': 0.29; 'sensible': 0.29; 'str': 0.29; 'starts': 0.29; 'compared': 0.30; 'up.': 0.32; 'computing': 0.32; 'subject:) ': 0.32; 'class': 0.33; 'skip:c 30': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'being': 0.37; 'received:org': 0.37; 'difference': 0.38; 'skip:- 20': 0.39; 'format': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'suitable': 0.61; 'show': 0.62; 'received:109': 0.75; '2.7.': 0.84; '3.4': 0.84; 'becker': 0.84
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host 109.174.168.73
X-Mozilla-News-Host news://news.gmane.org:119
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <7c1af35c-1ac7-96c7-3cba-ab9c8e542d8e@chamonix.reportlab.co.uk>
Xref csiph.com comp.lang.python:109006

Show key headers only | View raw


I had always imagined that the str founction did some kind of rounding on floats 
to prevent small numerical errors from showing up. The 2.7 documentation starts 
like this

> class str(object='')
> Return a string containing a nicely printable representation of an object. For s



However, I see a difference in the behaviour of python3.3, 3.4 & 3.5 when 
compared to python 2.7.

> C:\Users\rptlab>\python33\python.exe -c"print(str(3*0.2))"
> 0.6000000000000001
>
> C:\Users\rptlab>\python34\python.exe -c"print(str(3*0.2))"
> 0.6000000000000001
>
> C:\Users\rptlab>\python35\python.exe -c"print(str(3*0.2))"
> 0.6000000000000001
>
> C:\Users\rptlab>\python27\python.exe -c"print(str(3*0.2))"
> 0.6

I suppose I am being naive and should use the round function when computing tick 
labels, but that leads to other issues.

Is there a sensible way to take a set of floats and find a suitable format to 
show significant figures for all, but leave off the noise?
-- 
Robin Becker

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


Thread

str(float) python 3 versus 2.7 Robin Becker <robin@reportlab.com> - 2016-05-23 17:39 +0100

csiph-web