Format sum result with comma - Jquery

I am performing a sum of all values pertaining to a column of a table.

When returning par to html, it is being returned without the comma.

How can I proceed to have the comma shown in the second box ?

var valor_recibo = 0;

$(".valor_recibo").each(function() {
  var num = parseInt($(this).text().replace(/[^0-9]/g, ''));
  valor_recibo += num;
});

$('#totalrecibo').html(valor_recibo);

The value is returned in a span like this : 25998 The correct form is like this: 259,98

Html Code

<table class="table table-striped m-table m-table--head-bg-success">
  <thead>
    <tr>
      <th>Valor Recibo</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td class="valor_recibo">100</td>
      <td class="valor_recibo">200</td>
      <td class="valor_recibo">300</td>
      <td class="valor_recibo">400</td>
      <td class="valor_recibo">500</td>
    </tr>

  </tbody>
</table>
<div id="totalrecibo"> aqui retorna o valor </div>
Author: Sam, 2018-06-12

1 answers

parseInt will prevent you from working with decimal places. Instead, use parseFloat.

Also your replace is wrong. If NA td has only numbers, make a replace by replacing only the comma. JavaScript considers decimal places whatever comes to the right of the DoT, not the comma.

At the end of the calculation, you still need to convert the result to string and replace the semicolon:

var valor_recibo = 0;

$(".valor_recibo").each(function() {
  var num = parseFloat($(this).text().replace(',', '.'));
  valor_recibo += num;
});

$('#totalrecibo').html(valor_recibo.toString().replace('.', ','));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="table table-striped m-table m-table--head-bg-success">
  <thead>
    <tr>
      <th>Valor Recibo</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td class="valor_recibo">224,30</td>
      <td class="valor_recibo">237,60</td>
      <td class="valor_recibo">194,41</td>
    </tr>

  </tbody>
</table>
<div id="totalrecibo"> aqui retorna o valor </div>
 2
Author: Sam, 2018-06-12 02:22:06