File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes confusion in double operations... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "confusion in double operations..." Watch "confusion in double operations..." New topic
Author

confusion in double operations...

Vishal K Patel
Ranch Hand

Joined: Oct 20, 2006
Posts: 43


o/p : 20.79



o/p : 20.889999999999997

i think in 2nd case o/p should be 20.89...!!!
and actually i want the o/p 20.89.
what could be done..?

help me out...
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Hi,

Use printf():



or you can use:



Thanks,
[ May 30, 2007: Message edited by: Chandra Bhatt ]

cmbhatt
Prasad Tamirisa
Ranch Hand

Joined: Mar 26, 2007
Posts: 130
This is ok....But why is it happening so??

I mean,

why is it not 2.89 in 2nd case?
and why is it different in fist case?


Regards,
Durga Prasad
Prasad Tamirisa
Ranch Hand

Joined: Mar 26, 2007
Posts: 130
Can any one take a look at this?
Please.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Originally posted by Prasad Tamirisa:
Can any one take a look at this?
Please.


Tried Google for "floating point arithmetic accuracy" or similar? You will find discussions of floating point arithmetic accuracy in an elementary numerical mathematics course book.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Prasad Tamirisa
Ranch Hand

Joined: Mar 26, 2007
Posts: 130
Wow....! Thats a great reference.

Thanks once again barry. You have been so helpful to me these days.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Originally posted by Prasad Tamirisa:
Wow....! Thats a great reference.

Thanks once again barry. You have been so helpful to me these days.


Yes, I like to help people with initiative
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: confusion in double operations...