Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

124
Views
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 answers
Answer question

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 Report

0

i just converted to integer and it worked now

Number(doc.data().cashamout);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!