We are having some problems with calculations (divisions) in Java.
A sample program to show the problem:
public class NumberTest {
public static void main(String[] args) {
System.out.println("Double value: " + 27.8625d);
System.out.println("Float value: " + 27.8625f);
System.out.println("Double value: " + 1000.0d);
System.out.println("Float value: " + 1000.0f);
System.out.println("Double calculation: " + 27.8625d/1000.0d);
System.out.println("Float calculation: " + 27.8625f/1000.0f);
}
}
Output:
Double value: 27.8625
Float value: 27.8625
Double value: 1000.0
Float value: 1000.0
Double calculation: 0.027862500000000002
Float calculation: 0.027862499
I would expect the result of the calculations to be "0.0278625"
. Why is there a different result for both the float and double calculation?
Regards,
Tim