Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #109006
| From | Robin Becker <robin@reportlab.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | str(float) python 3 versus 2.7 |
| Date | 2016-05-23 17:39 +0100 |
| Message-ID | <mailman.25.1464021580.20402.python-list@python.org> (permalink) |
| References | <7c1af35c-1ac7-96c7-3cba-ab9c8e542d8e@chamonix.reportlab.co.uk> |
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
str(float) python 3 versus 2.7 Robin Becker <robin@reportlab.com> - 2016-05-23 17:39 +0100
csiph-web