Because of floating point rounding errors, you may never end up with a float, or a double, which is exactly 0.0 ( unless you set it yourself ). That is why i use the following technique:
An alternative is the following:
if ((val-ROUNDING_ERROR) <= test && (val+ROUNDING_ERROR) >= test)
Which one you'll choose to use is up to you. For performance sake, i suggest the second one, but for simplicity the first.
if (fabs(val-test) <= ROUNDING_ERROR) // I'm not sure if that way works
val :: The first number you want to compare
test :: The second number you want to compare
ROUNDING_ERROR :: typical float tolerance is 0.0000001f , for double tolerance i'm not sure
( You can even use your own tolerance by passing in to the function.