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

195
Views
Trying to add string starting from the right going to the left in a specific area

I've been trying to figure out how to add period as a string in a certain place, here's the code

function fixBalance(amount){
  if(amount <= 99999999){
    var amt = "0." + amount.toString().padStart(8, "0");
    return Number(amt);
  } else {
    return false;
  }
}

console.log(fixBalance(1));
console.log(fixBalance(1000));
console.log(fixBalance(10000000));
console.log(fixBalance(1000000000));

Basically, there are 8 spaces to the right of the 0

After it passes 8 numbers, I want numbers to keep going past the period

For example:

1 = 0.00000001

1000 = 0.00001000 or 0.00001

10000000 = 0.10000000 or 0.1

100001000 = 0.100001000

1000000001 = 10.00000001

1010000000 = 10.10000000

10100000000 = 101.00000000

If I were to put in 1000000000, it should be 10.00000000 or 10 as a numerical number

Trying to figure out how to do that with the else statement

Thank you!

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

0

How about determining the integer and decimal parts separately before composing them?

function fixBalance(amount){
  const divisor = 100_000_000;
  const integer = Math.floor(amount / divisor);
  const decimal = amount % divisor;
  
  return integer.toString() + "." + decimal.toString().padStart(8, "0");
}

console.log(fixBalance(1));
console.log(fixBalance(1000));
console.log(fixBalance(10000000));
console.log(fixBalance(1000000000));

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!