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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.