Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

198
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda