Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 30
    I needed to find the value in a range given the percentage. Taking this formula, I reworked it to val = ((percent * (max - min) / 100) + min Commented Feb 17, 2016 at 23:11
  • 1
    I suspect the formula can work when either one or both the range numbers are negative. Commented Feb 24, 2017 at 14:36
  • How would this work if the range has a negative number in either max or min? Commented Jul 2, 2019 at 20:36
  • @Daisy, well let's test it. If you're going from -10 to 10, then range is 10 - (-10) which is 10 + 10 and 20. Looks correct. Then assume input is 8. correctedStartValue would be 8 - (-10) = 18. That first looks strange, but lets keep going. The result would be (18*100) / 20 = 90%. And 90% looks fine to me for value 8 between -10 and 10. Commented Jul 2, 2019 at 20:46
  • @Daisy You only need to make sure that when both values are below 0, then max is the value with the largest absolute value. For example -50 and -20, then max=-50 and min=-20. Range will be -30, but that is fine. The negative sign is needed, since correctedStartValue will be negative as well. Commented Jul 2, 2019 at 20:48