aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes query about double addition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "query about double addition" Watch "query about double addition" New topic
Author

query about double addition

Alim Atar
Ranch Hand

Joined: Oct 06, 2006
Posts: 102

Hi,

I have a question about double addition in java 6. I tired following

double d1= 2.748 + 9.160;
System.out.println ( d1 );

I got following output 11.908000000000001 instead of 11.908 exactly.

Can anyone explain why it is so?


regards,
alim


Regards,
Alim

SCEA/OCMJEA Part1,SCBCD1.5,SCWCD1.4,SCJP1.4,SQL(Z007)
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
To get the exact output use BigDecimal.


SCJP 6,SCWCD 5,SCBCD 5

Failure is not an option.
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
probably this will help you to understand why the output is like that.


SCJP 1.6 96%
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: query about double addition