Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

83
Vistas
Javascript sum form fields with decimal values

I have a function that sums a bunch of total fields on a page. It could be one field or many. The number could be different every time. It is working correctly but not summing the two decimal places.

So for this list of numbers:

312.69
39.00

It outputs 351 instead of 351.69

Any ideas why this is based on the following code?

settotal() {
this.totalTarget.value = Number(this.qtyTarget.value * this.costTarget.value).toFixed(2)
var arr = document.getElementsByName('total');
var tot=0;
var totf=0;
for(var i=0;i<arr.length;i++){
    if(parseInt(arr[i].value))
        tot += parseInt(arr[i].value);
        totf = (Math.round(tot * 100) / 100).toFixed(2);

}
document.getElementById('invoice_net_amount').value = totf;

}

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda