This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Double result -- I was surprised

 
Rajiv Mellon
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See point 23 of the Javaranch Beginner's FAQ for more information.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic