Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a number range from 0-200 into 1-5 range

I have a value from 0 to 200 where 0 is better quality and 200 the worst quality.

How could I convert (In obj-c/cocoa framework) that to an integer from 0-5 being 5 best?.

For example 200 would be 0 and 0 would be 5.

like image 737
Benderian Avatar asked Dec 09 '22 11:12

Benderian


1 Answers

In general case if you have to transform Q = [A, B] to Q' = [A', B'], where f(A) = B' and f(B) = A', then an arbitrary X in space [A, B] will have for [A', B'] the following value:

X' = X * k + d;

where

k = (B' - A') / (A - B);

d = A' - B * k;

So, for your case we have A = 200, B = 0 and A' = 5, B' = 1, resulting:

k = -1/50

d = 5

an arbitrary value x from [0, 200] space will be translated as follow:

x' = x * (-1 / 50) + 5;
like image 199
Martin Babacaev Avatar answered Jan 01 '23 19:01

Martin Babacaev