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

127
Vistas
Calculate total from Firestore database

trying to get total price from three fields in fire store database

cashamout: '500000' cashamout: '46000' cashamout: "58000"

i am using the code below..but instead it gave me a result of 05000004600058000 instead of summing the value. Please what am i doing wrong?

 var totalCash = 0;
    this.adb.collection('cash').get().toPromise().then(function(querySnapshot) {
    querySnapshot.forEach(function(doc) {
      console.log('VALUESSS',doc.data())
        totalCash = totalCash + (doc.data().cashamout);
    });
    console.log('TOTALCLCLSLS',totalCash);
});
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Your numbers are not actually numbers at all. They are strings. You can tell because they will have quotes around them when viewing in the console.

When you "add" two strings, they are concatenated just like in the output that you showed.

If you want to store a number in Firestore, you should make sure that the input data is actually a JavaScript number type before you write the document, and not a string as they are now. This will allow them to sort and participate in math correctly.

about 4 years ago · Juan Pablo Isaza Denunciar

0

i just converted to integer and it worked now

Number(doc.data().cashamout);

about 4 years ago · Juan Pablo Isaza Denunciar
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