Java/Android – Set floating-point values – 0f and 0.0f

Java/Android – Set floating-point values – 0f and 0.0f … here is a solution to the problem.

Java/Android – Set floating-point values – 0f and 0.0f

I’ve been going through some Android source code and I’ve noticed that they use 0.0f to set the float value to 0. I know that 0 is an int and then implicitly converted to float and 0.0 is a double, but as far as I know, 0f is the same as 0.0f. Why would they struggle to enter an extra .0? 🙂

Solution

There is no other reason than style. 0f and 0.0f are the same value. See JLS§3.10.2

Related Problems and Solutions