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

177
Views
I need a simple code to remove decimal in my javascript

Here is my code. this showing a result with 8-9 decimal after main number. I want only 2 decimal to show after main number.

var data = resp.data
Object.keys(data).map(q => {
  Object.keys(data[q]).map(r => {
    console.log($('.rate_' + r + '_' + q), data[q][r])
    $('.rate_' + r + '_' + q).text(data[q][r] + '%')
  })
})
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can just use toFixed() to do that with the parameter being the number of digits after the decimal point. That assumes you have a Number already. If you have a string you need to parse it first using Number.parseFloat().

const test = 23213423.23423423;
console.log(test.toFixed(2));

const testStr = "23213423.23423423";
const parsed = Number.parseFloat(testStr);
if (!isNaN(parsed)) console.log(parsed.toFixed(2));
else console.log("The string is not a number!");

about 4 years ago · Juan Pablo Isaza Report

0

Here is a way using Math.round

const numbers = [
   1.1234567,
   10.14,
   0,
   44.178,
   15.1,
   23445.212124,
   2373872387283
];

numbers.forEach(x => {
   const result = Math.round(x * 100) / 100;
   console.info(result);
});

about 4 years ago · Juan Pablo Isaza Report

0

working example

const data = {
  a: { aa: 10.1234}, 
  b: {bb: 1.12345}
};

const out = [];
Object.keys(data).map( q => {
  Object.keys(data[q]).map( r => {        
    out.push(data[q][r].toFixed(2))
  })
})

console.log(out)

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!