Sum of the double value is showing wrong result.
public static void main(String[] args) {
Double d =0.0;
d += 300.10;
d += 300.10;
d += 300.10;
d += 600.19;
System.out.println(d);
}
Output is : 1500.4900000000002
Which is incorrect output. If you do addition in excel or normal calculator total value is 1500.49. But why java is adding extra decimal value 00000000002 for double only.
I have tested in Java 1.6 and 1.7 environments and found that if total double value falls in 1000.00 to 2000.00 then extra decimals 00000000001 is showing in java 1.6. But in Java 1.7 total double value falls in 1500.00 to 3000.00 then extra decimals 00000000002.
Why it is behaving for double value in Java?. Can anyone help me on this?
Thanks Vijaya Kumar Rasala IT-Engineer Palair,Khammam,Andhra Pradesh