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?
range = top_value - bottom_value
percent = (value - bottom_value) / range
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With