Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #89543
| References | <87twvzch2u.fsf@Equus.decebal.nl> |
|---|---|
| Date | 2015-04-29 21:55 +1000 |
| Subject | Re: str more precise in 3 as 2.7 |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.83.1430308536.3680.python-list@python.org> (permalink) |
On Wed, Apr 29, 2015 at 9:24 PM, Cecil Westerhof <Cecil@decebal.nl> wrote: > I am trying to make my modules also work under Python 3. I found that > str is more precise in Python 3. The expression: > str(134 / 6.0) > gives in 2.7.8: > '22.3333333333' > and in 3.4.1: > '22.333333333333332' > > Was not very hard to solve: > if python_version == 3: > output06[5] = '22.333333333333332' > output10[5] = '23.333333333333332' > output10[8] = '24.77777777777778' Try using repr() instead of str() - it might be more useful to you. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
str more precise in 3 as 2.7 Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 13:24 +0200
Re: str more precise in 3 as 2.7 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-04-29 12:50 +0100
Re: str more precise in 3 as 2.7 Chris Angelico <rosuav@gmail.com> - 2015-04-29 21:55 +1000
Re: str more precise in 3 as 2.7 Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 14:09 +0200
Re: str more precise in 3 as 2.7 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-30 14:29 +1000
csiph-web