Math: Percent that number is between two numbers

hankknight
hankknight used Ask the Experts™
on
How can I figure out what percentage that one number is between two other numbers?

For example, the price of Commodity X is currently $12.34 per pound.
This week's low price was $11.11 per pound and this week's high price was $22.22 per pound.

I tried solving this with JavaScript but I have the math wrong:

var low = 11.11;
var high = 22.22;
var current = 12.34;
alert( current * low / high ); // This is not correct

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
var low = 11.11;
var high = 22.22;
var current = 12.34;

var range = high - low;
var diff = current - low;
 
alert( (diff / range) * 100 + "%" );

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial