Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a percentage from a range [closed]

Tags:

algorithm

math

I have a basic math question. I am trying to get a percentage from a range of numbers and the algorithm is troubling me.

Say I have a range of -5 to +5 and I want to know what percentage is in between given a value. I know that -5 would be equivalent to 0% and 5 would be 100%, with 0 being 50%.

I tried to add 5 to bring up the scale, but it just feels like a hack. I would like it to feel dynamic so that I can give it any range and successfully work.

Ex.

percent = (5 + value) * 100 / 10

How do I figure out what value should be the a general case?

like image 644
Seb Avatar asked Jun 19 '12 18:06

Seb


1 Answers

range = top_value - bottom_value
percent = (value - bottom_value) / range
like image 137
Nathaniel Ford Avatar answered Oct 07 '22 19:10

Nathaniel Ford