1
I am making a sum of all the values related to a column of a table.
When returning even to html, it is being returned without the comma.
How can I proceed so that the comma is presented in the second house ?
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: 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>
The value is returned in a span like this : 25998 The correct form is like this : 259,98
– Robson Freitas
parseint converts to integer. exchange for parseFloat.
– Sam
I performed the exchange. but it still holds value without the comma.
– Robson Freitas
But then you have to see what you’re adding up. What values are you adding up?
– Sam
I am adding several <td class="receipt value_value">.
– Robson Freitas
you would like me to post html code ?
– Robson Freitas
It would be interesting.
– Sam
Let’s go continue this discussion in chat.
– Robson Freitas
I imagine the problem is in the regular expression. Try to change
/[^0-9]/g
for/[^0-9,]/g
.– Luiz Felipe