[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

decimal numbers

"Luke Geelen" <luke.geelen at gmail.com> wrote in message 
news:ec88852e-1384-4aa5-834b-85135be94ab9 at googlegroups.com...
> Op zaterdag 15 februari 2014 10:18:36 UTC+1 schreef Luke Geelen:
> 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)
> 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 ?

You don't say which version of python you are using.

If you are using python2, an integer divided by an integer always returns an 
integer -

>>> 10/3

It was changed in python3 to return a float -

>>> 10/3

You can reproduce the python3 behaviour in python2 by adding a 'future' 
directive -

>>> from __future__ import division
>>> 10/3


Frank Millman