A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Programmer Certification (SCJP/OCPJP)
== operator comparisons
Joined: Oct 13, 2006
Nov 01, 2006 19:35:00
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?
Joined: Feb 10, 2006
Nov 01, 2006 22:09:00
double d1= 2.5f;
double d2= 2.6f;
.. now i think you've got answer!
Sachin. [SCJP 1.4, SCWCD 5]
Joined: Nov 21, 2005
Nov 01, 2006 22:19:00
I am still not getting this. Can any one explain why value of 2.6f is 2.5999999046325684 ???
Joined: Mar 22, 2005
Nov 02, 2006 00:03:00
Check out the #21 in the
Java Beginners FAQ
. It links to articles that explain in detail what's going on.
Ping & DNS
- my free Android networking tools app
I agree. Here's the link:
subject: == operator comparisons
pls help on NaN
Issue adding double value
if(0.0 == -0.0) - Sample question
Question for Dan Wrapper Class
double & float related Qn
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014