The right way to compare a System.Double to ‘0’ (a number, int?)

Well, how close do you need the value to be to 0? If you go through a lot of floating point operations which in “infinite precision” might result in 0, you could end up with a result “very close” to 0.

Typically in this situation you want to provide some sort of epsilon, and check that the result is just within that epsilon:

if (Math.Abs(something) < 0.001)

The epsilon you should use is application-specific – it depends on what you’re doing.

Of course, if the result should be exactly zero, then a simple equality check is fine.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)