Adding float values from a Table

0

I'm trying to add the value of the fields of a table, but it's not working, with parseInt works, only it has values that are not going to be integers, so I put it as a float, but it does not perform the sum:

let result = 0;
let columns = $("#tablepesquisaprodutos tr td:nth-child(" + 5 + ")");

columns.each(i => {
    result += parseFloat($(columns[i]).html());
});
$("#DescontoP").val(result);
    
asked by anonymous 22.08.2018 / 19:44

1 answer

1

For your code, the difference was only toFixed in the view, so this answer from soen :

let result = 0;
let columns = $("#tablepesquisaprodutos tr td:nth-child(" + 5 + ")");

columns.each(i => {
    result = parseFloat(result ) + parseFloat($(columns[i]).html());
});
$("#DescontoP").val(result.toFixed(2));
    
22.08.2018 / 19:49