Possible Duplicate:
Retain precision with Doubles in java
Moving decimal places over in a double
The class speaks for itself. If you execute this code, the double values seem to be overflowed somewhat, but then it does not happen for all values and besides, if you print the number directly the output is OK.
public class test {
public static void main(String[] args){
for (double f=1.36; f<1.40; f+=0.01) System.out.println(f);
//Prints 1.36
// 1.37
// 1.3800000000000001 ???????
// 1.3900000000000001 ???????
System.out.println(1.36); //Prints 1.36
System.out.println(1.37); //Prints 1.37
System.out.println(1.38); //Prints 1.38
System.out.println(1.39); //Prints 1.39
}
}
Can somebody shed some light? If this is a bug, whats´s the best way to fix it in the code?? Any magic workaround?