This is normal.
You are returning a double
in scientific notation.
The println
method in this case will print out the equivalent of String.valueOf(yourDoubleValue)
Real literals are implicitly interpreted as primitive double
s unless specified otherwise.
To force interpretation to float
you need to append f
to your literals, although it won't change the fact that your result will be printed in scientific notation and with possible loss of precision:
System.out.println(0.9623f - 0.9619f);
Output
4.0000677E-4
I suspect what you ultimately want to print is:
System.out.println(new BigDecimal("0.9623").subtract(new BigDecimal("0.9619")).toPlainString());
Output
0.0004
More on BigDecimal
here.