2
I have two input fields where I type values. I put mask so that when type the value is in the format 0,00. How do I make a simple calculation with values 0.00? Because I have a formula that I passed and that the result, either from 0 or appears Nan. Follows the code of the formula, of the calculation.
$(function(){
$("#precoVendaNoMercado, #descPromo , #descFinan ").change (function(){
if($("#precoVendaNoMercado").val() != "" && $("#descPromo").val() != "" && $("#descFinan").val() != "") {
precoDeVendaRealizado = parseFloat($("#precoVendaNoMercado").val() * (1- (parseFloat($("#precoVendaNoMercado").val())) + parseFloat($("#precoVendaNoMercado").val())) / 100 );
console.log('Calculo:'+precoDeVendaRealizado);
}
});
});
I did what you suggested @Diego Souza. And on Chrome console points to the line:
var desFinan = descFinan.replace('.', '').replace(',', '.'); precoDeVendaRealizado = precoVeNoMerc * (1 - (desPromo + desFinan) / 100 );
Saying "Uncaught Typeerror: Cannot read Property 'replace' of Undefined"
you’re always counting the
$("#precoVendaNoMercado").val()
, is correct? It shouldn’t be:precoDeVendaRealizado = parseFloat($("#precoVendaNoMercado").val() * (1- (parseFloat($("#descPromo").val())) + parseFloat($("#descFinan").val())) / 100 );
– CesarMiguel
Can you give examples of values you have? The mask also adds points?
– Sergio
@Sergio, I’m turning my data into float, with parseFloat, but when we are penny values, the result does not appear with that penny, example: 1,11 + 1,11 the result is only 2 and not 2,22. After converting the data into float, I do the following: variavel1 + variavel2, it is wrong?
– GustavoSevero