I would like this code to take the cents of the value coming from the javascript variable
preco = parseInt(preco);
I've put it like this
preco = parseFloat(preco);
Full code below
total = 0;
function adiciona(id) {
calcula(id, "adicao");
}
function remove(id) {
calcula(id, "subtracao");
}
function calcula(id, operacao) {
nomeid = "nome" + id;
precoid = "preco" + id;
qtdid = "qtd" + id;
nome = document.getElementById(nomeid).innerHTML;
preco = document.getElementById(precoid).innerHTML;
preco = parseInt(preco);
qtd = document.getElementById(qtdid).innerHTML;
qtd = parseInt(qtd);
//Debug
//alert("Produto: " + nome + "\n Preço: " + preco);
if (operacao == "adicao") {
total = total + preco;
qtd = qtd + 1;
} else {
total = total - preco;
qtd = qtd - 1;
}
document.getElementById(qtdid).innerHTML = qtd;
document.getElementById("total").innerHTML = total;
}