I am using the following simple JavaScript code to calculate the percentage difference between two values:
subOBS001 = (vars.obs001acount) - (vars.obs001asent);
divOBS001 = (subOBS001) / (vars.obs001asent);
modOBS001 = (divOBS001) * (100);
if (modOBS > 30) {%> <%= modOBS %><span id="greenStatus">•</span> <%} else {%> <%= modOBS %>
Is there a simpler way to perform my calculation? Have it all in one single line using parenthesis?
I am using the following simple JavaScript code to calculate the percentage difference between two values:
subOBS001 = (vars.obs001acount) - (vars.obs001asent);
divOBS001 = (subOBS001) / (vars.obs001asent);
modOBS001 = (divOBS001) * (100);
if (modOBS > 30) {%> <%= modOBS %><span id="greenStatus">•</span> <%} else {%> <%= modOBS %>
Is there a simpler way to perform my calculation? Have it all in one single line using parenthesis?
Share Improve this question edited May 13, 2014 at 17:03 dertkw 7,8585 gold badges38 silver badges45 bronze badges asked May 13, 2014 at 16:53 David GarciaDavid Garcia 2,69618 gold badges61 silver badges94 bronze badges 3-
4
%> <%= modOBS %>
... that doesn't look like simple JS code to me! – Niet the Dark Absol Commented May 13, 2014 at 16:54 - JScript + Classic ASP? – Alex K. Commented May 13, 2014 at 17:01
- 1 This is a phantomjs which is a js interpreter used in crm tools, the '<%' tag is to let the tool know this is a js code block – David Garcia Commented May 14, 2014 at 8:19
1 Answer
Reset to default 7Your calculation done on one line, if that is what you want:
modOBS001 = (vars.obs001acount - vars.obs001asent) / vars.obs001asent * 100;
And if your math is correct and you want the value of vars.obs001asent
represent 100%.