Floating point comparisons can be tricky. They are handled differently. I would suggest that you choose to what decimal place you want to be accurate to. For example, if I wanted to know if
double a = 1.902456;
double b = 1.902478;
if(a==b)
and I only cared about 3 decimal places here is what I would do.
int val1 = (int)(a*1000);
int val2 = (int)(b*1000);
NOTICE The parens... just make sure you cast appropriately.
then
val1+= ((int)(a*10000))%10 >=5 ? 1:0;
val2+= ((int)(a*10000))%10 >=5 ? 1:0;
return val1 == val2
In this case it will return true;
if b was = to 1.902578, val2 would be rounded up to 1903 and this would return false.
Matt