Calculating the percentage difference of two numbers The basic problem is this: "I have this number x and I ask you to give me another number y. If the number you give me is some percentage c different than my number then I do not want it." Given that you will know x and c, how do you calculate whether or not I should take y?
The naive approach I came up with is to just divide y / x < c but this fails for obvious reason (try y bigger than x).
The next approach I is that the percentage difference is really just a ratio of the smaller number divided by the larger number. So thereforce we could try min(x, y) / max(x, y) < c. However this does not work, here is an example:
x = 1.2129 y = 1.81935 c = 50%
If we do the above we get 1.2129 / 1.81935 = 0.67 which is greater than 0.50. The problem here is that I obtained y by multiplying 1.2129 by 1.5, therefore y is only 50% greater than x. Why? I still don't understand why the above formula doesn't work.
Eventually through some googling I stumbled accross the percentage difference formula but even this doesn't suit my needs. It is abs(x - y) / ((x + y) / 2). However, this does not yield the result I am looking for. abs(x - y) = abs(1.2129 - 1.81935 ) = 0.60645. (x + y) / 2 = 3.03225 / 2 = 1.516125 0.60645 / 1.516125 = 0.4
Eventually I ended up writing some code to evaluate x * c < y < x * (1 + c). As the basic idea is that we don't want any y that is 50% less than my number, nor do we want any number that is 50% greater than my number.
Could someone please help me identify what I'm missing here? It seems like there ought to be another way that you can calculate the percentage difference of two arbitrary numbers and then compare it to c.

As far as I understood, you want the difference between two numbers (x-y) to be c(or less)% different than your number (x). 
When you use min(x, y) / max(x, y) < c, you are calculating whether minimum of two numbers is c(or less)% smaller than maximum of them. 
abs(x - y) / ((x + y) / 2) calculates whether the difference between two numbers (x-y) is c(or less)% different than average of those two numbers. 
Those are completely different problems.
For yours, abs(x-y)/x < c should work.
