I need some help to convert and add fields formatted as currency coming in this format "1,568,78"
I have a code that sums an array of plots and checks if it is equal to the total phallus of the invoice I got here after several queries in user responses, and works perfectly with integer numbers, but when I type the number formatted in reais it does not sum:
var quant = document.getElementsByName("valor[]");
function somarValores(){
var valor_fatura = parseInt(document.getElementById('valor_fatura').value);
var soma = 0;
var soma = [].reduce.call(quant, function (somatorio, el) {
return somatorio + parseInt(el.value, 10) || 0;
}, 0);
if(soma != valor_fatura){
alert('Valor não confere. Fatura='+valor_fatura+' - Parcelas='+soma+'');
return false;
}
}
I then assume that I have to convert the "quant" and "value_value" variables to 1568.78 before calculating because it is rounded to integers and disregards the cents causing my validation error