title: How to convert cell value to int and compute for its difference using apps script
body: <p>Is there a way to convert cell values to integer using apps script and display its difference in specific column? I have this sheet database that contains fields in the picture, <a href="https://i.stack.imgur.com/iy4F0.png" rel="nofollow noreferrer">1</a> and using apps script, I wanted to compute columns M and N automatically using apps script. Column M (Remaining Qty) should be the difference between balance_qty column and issue_qty column if balance_qty is greater than restock_point otherwise, column M (Remaining Qty) would be the difference between balance_qty and restock_point. For the column N (Replenish Qty) it should be the difference between issue_qty and balance_qty if balance_qty is less than the issue_qty. I tried to make a script below:</p>
  <pre><code>function calc() {
  
      var ss = SpreadsheetApp.getActive();
      var range = ss.getSheetByName(&quot;Database&quot;).getRange(&quot;datas&quot;).getValues();
  
      for(var x = 0; x &lt; range.length ; x ++){
  
      var balance = range[x][7];
      var issue = range[x][4];
      var receipt = range[x][12];
      var pr = range[x][13]
      var rPoint = range[x][8];
  
      if(balance &lt; 0){
   
        pr.setValues(balance.toString());
        receipt.setValues(0)
  
      }else if(balance &lt; issue){
  
        var diff = issue - balance;
        var rec = balance - rPoint
  
        pr.setValues(diff.toString());
        receipt.setValues(rec.toString());
  
      }else{
  
        var rem = balance - issue;
        receipt.setValues(rem.toString());
  
      }
    }
  }
  </code></pre>
  <p>but it still missing something.</p>
  <p>Note: That the range &quot;data&quot; is cell from A4:N19</p>