import math
print(math.ceil(0.5))
Returns
1.0
But
import math
print(math.ceil(1/2))
Returns
0.0
What's going on here? Explanation would be nice.
import math
print(math.ceil(0.5))
Returns
1.0
But
import math
print(math.ceil(1/2))
Returns
0.0
What's going on here? Explanation would be nice.
It seems you're running that code using python 2.x where you need to cast to float explicitely:
import math
print(math.ceil(0.5))
print(math.ceil(float(1) / float(2)))
If you run python 3.x you won't need to do that cast explicitely and you'll get the same output:
import math
print(math.ceil(0.5))
print(math.ceil(1 / 2))
import math
print(math.ceil(1/float(2)))