private static final double is 0-Collection of common programming errors
The constant ends up with a value of 0.0
because the result of integer division is an integer, truncated. So your the value of your initialization is 0
, not 0.5
. To force a double
result, make one or both of the operands a double
:
private static final double CONSTANT = 1/2.0; // or 1/2D, or even 1D/2D