I am facing difficulty in comparing two double values
using ==
and !=
.
I have created 6 double variables and trying to compare in If
condition.
double a,b,c,d,e,f;
if((a==b||c==d||e==f))
{
//My code here in case of true condition
}
else if ((a!=b||c!=d||e!=f))
{
//My code here in case false condition
}
Though my condition is a and b are equal
control is going to else if
part
So I have tried a.equals(b)
for equal condition, Which is working fine for me.
My query here is how can I check a not equal b
.. I have googled a lot but I found only to use !=
but somehow this is not working for me.
Experts please help me to overcome this.
Thanks for your time.
If you're using a
double
(the primitive type) thena
andb
must not be equal.If
.equals()
works you're probably using the object wrapper typeDouble
. Also, the equivalent of!=
with.equals()
isEdit
Also,
(Unless I'm missing something) should just be
if you really want invert your test conditions and test again,
Or use De Morgan's Laws
You can use
Well with double data type you can use