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

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

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 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