I have following test code snippet, which has a float type variable f
, and I have assigned the value 3627.299685
to it.
After that, I am creating one more variable d2
of type double, by typecasting f
to double.
Printing the values of both f
and d2
, my observation results are bit weird, as both the variable values do not match exactly the value assigned to the variable.
Is it limitation of the Java 1.7.0_97, 64Bit server? Or is there any other way, we can print the exact value of the variable here?
public class TestFloat {
public static void main(String[] args) {
float f = 3627.299685f;
double d2 = (double)f;
System.out.println("Float:" + f);
System.out.println("Float converted to Double:" + d2);
}
}
user@test01:/tmp$ java TestFloat
Float:3627.2998
Float converted to Double:3627.2998046875