+ 2

Floor Division on Floating Numbers--

Why is it that Floor Division on a Floating Number, e.g "12.0//6" does not return an integer, being "2", but instead returns another Floating Number, being "2.0"?

30th Dec 2016, 8:17 PM
ₚsʸ
ₚsʸ - avatar
2 Réponses
+ 2
Because if either member is float, the return value is also float. In the case you want integer result, you can retype it with (int) value.
30th Dec 2016, 8:34 PM
Heroes Killer
Heroes Killer - avatar
0
"12.0//6" is showing "2.0" because "12.0" is a floating number and "6" is int, but as the rule suggests the interpreter implicitly converts the result into floating point number. The operation gives the integer result but due the nature of one of the input it is converted into floating point after the operations is performed.
30th Dec 2016, 10:08 PM
Ravishankar Chaubey
Ravishankar Chaubey - avatar