Add float values from a Table

Asked

Viewed 61 times

0

I’m trying to add the value of the fields of a table, but it’s not working, with parseint it works, only it has values that won’t be integers, so I put it as a float, but it doesn’t 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);

1 answer

1


For your code the difference was only the toFixed in the exhibition, second that soen response:

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));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.