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

218
Vistas
Format number to always show how many 0's

I would like to format my numbers to display and replace how many 0's after three 0's

Examples:

number     display
------     -------
0.000001   0.0₅1
0.0000003  0.0₆3
0.001      0.001
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This is an example how you can achieve this. I have commented the code. Feel free to modify the example yourself if you wish.

const convert = num => {
  const subs = [ '₀', '₁', '₂', '₃', '₄', '₅', '₆', '₇', '₈', '₉' ]
  const [left, right] = num.toFixed(10).split('.') // break a number by the dot
  const result = right.match('^([0]{3,})') // for 000 and more zeroes
  if (result){
    const length = result[0].length; // get subs size
    return(left + '.0' + subs[length] + right.slice(length)) // join all parts
      .replace(/0+$/, '') // remove zeroes from the end
  } 
  return num // original
}

console.log([0.000001, 0.0000003, 0.001].map(convert)) 

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