I am trying this in Python 2.7 Interpreter.
>>> print 1/10
0
>>> print float(1/10)
0.0
>>> print 1/5
0
>>> a = 1/5
>>> a
0
>>> float(a)
0.0
>>>
I want a value in floating point when I divide. Any idea on the logic behind this zero out put and please let me know how to do it correctly.
The float conversion is happening after the integer division. Try this:
>>> print(1.0/10)
0.1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With