Function that takes a value and return a percentage

46 Views Asked by At

I can't figure out how to create a function that takes as input a value between 0 and 180 and returns a percentage:

For a value 1 for example : 176 return 100%

For a value 2 for example : 86 return 0%

and return a big value of percentage if the value is near value 1 for example: 176

and return a small value of percentage if the value is near value 2 for example: 86

I created the image below to simplify my problem :

Image1

Edit 1 : The input of the function is always between 0 and 180.

1

There are 1 best solutions below

0
On

If the first value is $a$ and the second is $b$, you have $$f(x)=\frac {x-b}{a-b}\cdot 100\%$$