I got a really strange problem about adding 2 doubles.
double a = 2.3 + 3.4;
System.out.println(a);
the result will be 5.699999999999.
Can anybody explain it for me!!!!!
Printable View
I got a really strange problem about adding 2 doubles.
double a = 2.3 + 3.4;
System.out.println(a);
the result will be 5.699999999999.
Can anybody explain it for me!!!!!
Read Goldberg's article and you know all.
kind regards,
Jos
U have to determine the number of digits after the decimal point, this problem is related to the binary representation of doubles and intgers, it usually happens that's why it is better to determine the number of digit after the decimal point u want to represent, this will force the rounding of the result and fix this calculation error