I have 12 different numbers stored in variables, like this:
var span1 = 8.333333333;
var span2 = 16.66666667;
var span3 = 25;
var span4 = 33.33333333;
var span5 = 41.66666667;
var span6 = 50;
var span7 = 58.33333333;
var span8 = 66.66666667;
var span9 = 75;
var span10 = 83.33333333;
var span11 = 91.66666667;
var span12 = 100;
I have a function which compares a div’s width to its parent’s width and returns a value as a percentage (minus the % sign), for example, 48.5586. I’d like the function to check which of these span variables the result is closest to. For example, 48.5586 would return "span6" as it’s closer to 50 than 41.666667.
Don’t really know where to start with this one, any ideas?
Since each span is 8 1/3 % more than the previous one, which is just
100/12, you should be able to use a formula to work out which span class you need.I worked out the following:
This gives
span6for 48.5586.