1. Member
Join Date
Apr 2012
Posts
1
Rep Power
0

double a = 2.3 + 3.4;
System.out.println(a);
the result will be 5.699999999999.
Can anybody explain it for me!!!!!

2. ## Re: Problems with adding double.

Originally Posted by ngoc09

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

3. Member
Join Date
Jan 2011
Location
Beirut, Lebanon
Posts
90
Rep Power
0

## Re: 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

4. ## Re: Problems with adding double.

Originally Posted by baf06
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
Determining the representation of IEEE754 floaing point numbers doesn't fix any calculation errors. Read the link I supplied in my previous reply.

kind regards,

Jos

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•