Here are two variables: earnings_forecast
, actual_earning
(numerical variables)
I want to assert if both these variables are equal with a diffe
abs(earnings_forecast - actual_earning) < 0.01 * abs(earnings_forecast + actual_earning)
is a nice way of doing it, which gives you a good symmetric 2% difference on either side. It also doesn't suffer from pitfalls that can arise of one of the values is zero.
There are other definitions, but like the one above, they have their own pros and cons.