Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #66460
| References | <833583c7-c307-4ebf-9a60-3be146a565b5@googlegroups.com> |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | 2014-02-15 10:20 -0700 |
| Subject | Re: decimal numbers |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.7010.1392484878.18130.python-list@python.org> (permalink) |
On Sat, Feb 15, 2014 at 2:18 AM, <luke.geelen@gmail.com> wrote: > hello, > i have been working on a python resistor calculator to let my class show what you can do with python. > now i have a script that makes the more speekable value of the resistance (res) > > #if len(str(res)) > 9: > # res2 = res / 1000000000 > # print "de weerstand is %s,%s giga ohms" % (res2) > #elif len(str(res)) > 6: > # res2 = res / 1000000 > # print "de weerstand is %s,%s Mega ohm" % (res2) > #elif len(str(res)) > 3: > # res2 = res / 1000 > # print "de weerstand is", res2,"kilo ohm" > #elif len(str(res)) < 4: > # res2 = res > # print "de weerstand is", res2,"ohm" > > i commented it because it doesn't work (yet), when i have a resistance of > 9.9 Giga ohms it says it is 9 giga ohms. it seems to work with natural number, anyway of using decimals insted so that it says : the resistance is 9.9 Giga Ohms instead of 9 ? Others have already explained how to do floating-point rather than integer division. I'm curious to know why you're basing the if tests on the length of the number as a string rather than on the magnitude of the number. Consider for example an input of 0.01. Converted to a string, that is "0.01" which has a length of 4. So the output would be "de weerstand is 0.00001 kilo ohm", which is probably not what you would desire.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
decimal numbers luke.geelen@gmail.com - 2014-02-15 01:18 -0800
Re: decimal numbers Luke Geelen <luke.geelen@gmail.com> - 2014-02-15 01:19 -0800
Re: decimal numbers "Frank Millman" <frank@chagford.com> - 2014-02-15 12:04 +0200
Re: decimal numbers Luke Geelen <luke.geelen@gmail.com> - 2014-02-15 02:32 -0800
Re: decimal numbers "Frank Millman" <frank@chagford.com> - 2014-02-15 12:49 +0200
Re: decimal numbers Luke Geelen <luke.geelen@gmail.com> - 2014-02-15 09:17 -0800
Re: decimal numbers Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-15 10:23 -0700
Re: decimal numbers Luke Geelen <luke.geelen@gmail.com> - 2014-02-15 09:42 -0800
Re: decimal numbers Luke Geelen <luke.geelen@gmail.com> - 2014-02-15 10:57 -0800
Re: decimal numbers Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-15 19:06 +0000
Re: decimal numbers Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-15 19:43 +0000
Re: decimal numbers Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-15 14:34 -0700
Re: decimal numbers Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-16 02:30 +0000
Re: decimal numbers Chris Angelico <rosuav@gmail.com> - 2014-02-16 13:36 +1100
Re: decimal numbers "Frank Millman" <frank@chagford.com> - 2014-02-15 12:56 +0200
Re: decimal numbers Chris Angelico <rosuav@gmail.com> - 2014-02-15 21:13 +1100
Re: decimal numbers Laurent Pointal <laurent.pointal@free.fr> - 2014-02-15 15:52 +0100
Re: decimal numbers Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-15 10:20 -0700
Re: decimal numbers wxjmfauth@gmail.com - 2014-02-16 04:19 -0800
csiph-web