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

- 04-26-2012, 11:24 AMngoc09Problems with adding double.
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!!!!! - 04-26-2012, 11:33 AMJosAHRe: Problems with adding double.
Read Goldberg's article and you know all.

kind regards,

Jos - 04-26-2012, 11:36 AMbaf06Re: Problems with adding double.
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

- 04-26-2012, 12:16 PMJosAHRe: Problems with adding double.