title: Javascript: percentage difference between two values
body: <p>I am using the following javascript code to display the difference in percentage between two values.</p>
  
  <pre><code>A = 11192;
  B = 10474;
  
  percDiff = (vars.A - vars.B) / vars.B * 100;
  </code></pre>
  
  <p>Which gives: 6.855069696391064</p>
  
  <p>Then</p>
  
  <pre><code>if (percDiff &gt; 20) {
    //dosomething
  } else {
    //dosomething
  }
  </code></pre>
  
  <p><strong>The problem is:</strong></p>
  
  <p>If value B is higher than value A then i get a NaN, for instance;
  <img src="https://i.stack.imgur.com/wKJ83.jpg" alt="NaN"></p>
  
  <p>How can I overcome this issue? I thought about using <code>Math.abs()</code> </p>
  
  <p>Any suggestions?</p>