title: Doing subtraction on JavaScript
body: <p>I have 3 column, and I'm trying to do some subtraction of two column on JavaScript. The first column's (column A) data are from the database, for the second column's (column B) data are user input, and the third column is for the value. I have successfully run the addition, but actually, what I want is subtraction. I have tried changing the sign + to - but turns out give me the wrong value. Can anyone help me?</p>
  
  <p>this is my code</p>
  
  <pre><code>&lt;tr&gt;
                          &lt;td style="text-align: center; vertical-align:middle;"&gt;&lt;?php echo $no; ?&gt;&lt;/td&gt;
  
                          &lt;td style="vertical-align:middle;"&gt;&lt;?php echo $data[$i]['nama_barang']?&gt;&lt;/td&gt;
  
                          &lt;td style="text-align: right; vertical-align:middle;" class="so"&gt;&lt;?php echo $data[$i]['stock']; ?&gt;&lt;/td&gt;
  
                          &lt;td&gt;&lt;input type="number" class="form-control so" id="stock_op" name="stock_op" style="text-align: left"&gt;&lt;/td&gt;
  
                          &lt;td style="text-align: right; vertical-align:middle; font-weight:bold;"&gt;&lt;output class="result"&gt;&lt;/output&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;?php                                           
                      }
                  ?&gt;
      &lt;script src="../js/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script&gt;
      $(document).on('input','.so',function(){
  var grandSum = 0;
          var totalSum = 0;
          var currentRow = $(this).closest('tr');
          currentRow.find('.so').each(function(){
              var inputVal = ($(this).is('input')) ? $(this).val() : parseInt($(this).html());
              if($.isNumeric(inputVal)){
                  totalSum += parseFloat(inputVal);
              }
          });
          currentRow.find('.result').val(totalSum);
      });
  
      &lt;/script&gt;
  
                  &lt;/tr&gt;
  </code></pre>
  
  <p>This is the table <img src="https://i.stack.imgur.com/fVjut.png" alt="UI"></p>