0

For 3/4 operation it's showing 0 not 0.75, why.!?

I've installed python version 2.7, and float thing is not properly shown ie. showing integer value. as 10/2 should show 5.0 instead showing only 5.

8th Jan 2017, 10:14 AM
Nitesh Dudhe
Nitesh Dudhe - avatar
5 Respostas
+ 4
In Python < 3.x, division ( / ) is integer if both operands are integer. You must explicit at least one of the argument as float to have a float returned... try: 3.0/4 # will return 0.75 Since Python 3, the division ( / ) return a float in all case, when you need to use the double slash operator ( // ) for integer division... To reproduce this behaviour in Python 2.7, you can add: from __future__ import division ... on begining of your script ;) [ EDIT ] Or before you attempt to calculate a division, in a command line interpretor, once per session...
8th Jan 2017, 10:26 AM
visph
visph - avatar
0
let me see your code!
8th Jan 2017, 10:16 AM
tonny
tonny - avatar
0
It's a simple operation... 3/4 which should give me0.75 bt gives output of 0
8th Jan 2017, 10:18 AM
Nitesh Dudhe
Nitesh Dudhe - avatar
0
Thank you just now figured out. And answer was posted.
8th Jan 2017, 10:31 AM
Nitesh Dudhe
Nitesh Dudhe - avatar
0
yes and this issue is with python< 3.x...thanks for this too.
8th Jan 2017, 10:32 AM
Nitesh Dudhe
Nitesh Dudhe - avatar