I have the following function, which takes the total of the invoice, adds the amounts that have been paid, subtracts them and obtains the total that remains to be paid:
function PagarTotal(){
var total_a_pagar = $('#total_a_pagar').val();
var pagado = 0;
for(i in pagos_adicionados){
pagado += Number(pagos_adicionados[i]['monto_pago']);
}
total_a_pagar = Number(total_a_pagar) - Number(pagado);
$('#monto_pago').val(total_a_pagar);
}
The problem is the following, in a simple transaction, with a bill of $ 5.35, payment $ 2 and the total to pay me back 3.3499999999999996, I do not understand where many decimals come from, by logic subtracting this should give a total from: $ 5.35 - $ 2 = $ 3.35
I've tried parseFloat and Number and the same thing happens with both functions.
Note: I can not use toFixed because this would round out the amounts and is not what I need, toFixed is practically a PATCH to fix this error timelessly.