最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Percentage difference between two values - Stack Overflow

programmeradmin1浏览0评论

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">&#8226;</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">&#8226;</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
Add a ment  | 

1 Answer 1

Reset to default 7

Your 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%.

发布评论

评论列表(0)

  1. 暂无评论