Wait what?
float f = (short) 0.50 f;
The result is 0.0
So.....
float 0.50 gets casted to short so we cut the fractional part and get 0, and then cast it again to float and get 0.0??
that is crazy
Float f
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
ImDevin
1 June 2021, 16:58
that used to look crazy to me too! somehow it doesn't anymore. :) But, what John said is right. As 0.50 narrows to short, it throws away anything that's not a whole number; and as it widens(automatically), it takes on a decimal, as float is a decimal; therefore it becomes 0.0 Happy coding! :)
0
John
1 June 2021, 12:51
because short only accepts whole numbers causes thw result to become 0. then the variable has been modified and changed to 0 thats why when you cast it back to float the result would be 0.0
0