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

189
Views
Vue.js - rounding off digits giving me bizarre figures

I'm calculating my totals and then i want them to be fixed to 2 decimal places.Check my code below.

this.selectedCompaniesDetails.forEach((company)=>{
                            if(company.id == p.company_id)
                            {
                                if (!tot[p.company_id])
                                {   tot[p.company_id] = [] }
                                    const numberPrice = parseFloat(p.price)
                                
                                 tot[p.company_id].push(numberPrice)
                            }
                        });

The parseFloat(p.price) function is giving me weird answers. Check my screen shot below. enter image description here

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Try something like this,

let num = 5.56789;
let n = num.toFixed(2);

console.log(num);
console.log(n);

about 4 years ago · Juan Pablo Isaza Report

0

use Math.round(num + "e+2") + "e-2"

function roundToTwo(num) {
   return +(Math.round(num + "e+2")  + "e-2");
}

let number = 139.605;
let round = roundToTwo(number)
var f = number .toFixed(2);

console.log('original', number);
console.log('expected', 139.61);
console.log('(Correct)round', round);
console.log('(Wrong)toFixed', f);

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!