Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

126
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

0

i just converted to integer and it worked now

Number(doc.data().cashamout);

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda