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 Double result -- I was surprised Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Double result -- I was surprised" Watch "Double result -- I was surprised" New topic
Author

Double result -- I was surprised

Rajiv Mellon
Greenhorn

Joined: Feb 28, 2006
Posts: 1
Hi everyone

When I executed the following code I was surprise to see the result.I got the output 'a' but I thought logically it should be 'b'. Why this is happening I just multiplied two number which is infact double. I would appreciate any help.

Thank you
Raj

public class FirstClass {

public static void main(String[] args) {
FirstClass fr = new FirstClass();
fr.test();
}

public void test(){
double inp = 178.5030;
inp = 178.5030 * 10000;
System.out.println("output --->"+inp);
}

Output:
a)output --->1785029.9999999998
b)output --->1785030.00
[ February 28, 2006: Message edited by: Rajiv Mellon ]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18715
    
  40

See point 23 of the Javaranch Beginner's FAQ for more information.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Double result -- I was surprised