Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

== operator comparisons

 
Guangcheng Zhou
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I was wondering why the following code is printing true and false.

double d1 = 2.5;
double d2 = 2.6;
System.out.println(d1 == 2.5f);
System.out.println(d2 == 2.6f);

Shouldn't they be printing the same boolean value at least?


Thanks,


Mack
 
sachin poddar
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this..
double d1= 2.5f;
double d2= 2.6f;
System.out.println(d1);
System.out.println(d2);
.. now i think you've got answer!
 
pranav thakker
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am still not getting this. Can any one explain why value of 2.6f is 2.5999999046325684 ???
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the #21 in the Java Beginners FAQ. It links to articles that explain in detail what's going on.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic