Lets say I would like to calculate percents and do:
double n = ...;
double total = ...;
double percents = (total == 0) ? 0 : (n/ total) * 100;
R# warns me “Fix floating number compare”. And hints of using EPSILON. I clearly understand why this warning is showed in general. But in this case the only I want, is to avoid throwing exception. So I “state” on fixed 0.
Is it right assumption or there are some hidden flaw and I should use some epsilon anyway?
Nothing wrong with floating-point dividing by 0.0.
You only get DivideByZeroExceptions for integer division.
The problem you get though is that 1.0/0.0 results in Infinity.
If this is for displaying, just use
string.Format.