You must already be bald to see problems like this. My problem, I think, is a bit different.
I have a method (called transformAccounts) that transforms any type of monetary value to be able to calculate. However, even if I am changing, I can not use these numbers to add up. I made a method to check if the return of the AccountTransform is really numeric, but always true.
Methods:
function transformaParaContas(value){
if(value.indexOf(".") >= 0){
value = value.replace(/\./g, "");
}
value = value.replace(",", ".");
value = Number(value);
value = value.toFixed(2);
return value;
}
// metodo para verificar se é realmente um número
function isNumber(numero){
return !isNaN(numero);
}
// disparo
$("input[name='txt_valNaoProcedente']").on("keypress", function(){
var valProc, valNaoProc, total;
valProc = $("input[name='txt_valProcedente']").val();
valNaoProc = $("input[name='txt_valNaoProcedente']").val();
if(valProc != "" && valNaoProc != ""){
valProc = transformaParaContas(valProc);
valNaoProc = transformaParaContas(valNaoProc);
console.log(isNumber(valProc));
console.log(isNumber(valNaoProc));
total = valProc + valNaoProc;
$("#div_valorDebito").text(valProc + valNaoProc);
}else{
$("#div_valorDebito").text("");
}
});
If I do the following, it works:
$("input[name='txt_valNaoProcedente']").on("keypress", function(){
var valProc, valNaoProc, total;
valProc = $("input[name='txt_valProcedente']").val();
valNaoProc = $("input[name='txt_valNaoProcedente']").val();
if(valProc != "" && valNaoProc != ""){
valProc = transformaParaContas(valProc);
valNaoProc = transformaParaContas(valNaoProc);
valProc = Number(valProc);
valNaoProc = Number(valNaoProc);
console.log(isNumber(valProc));
console.log(isNumber(valNaoProc));
total = valProc + valNaoProc;
$("#div_valorDebito").text(valProc + valNaoProc);
}else{
$("#div_valorDebito").text("");
}
});
Would anyone please explain why this happens?