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

217
Vistas
Integer price number to float Javascript

I am interacting with an API and it returns the price as in integer, for example:

99.59 is returned from the API like this: 9959

60.00 is returned like this 6000

252.90 is returned like this 25290

I'd love a function that takes in the integer number and turns it to float exactly like the above, so 25290 should be 252.90 and 9959 should be 99.59

Any help Is really appreciated.

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You can use something like this.

const formatNumber = (value, precision = 2) => {
    return (value / 100).toFixed(precision);
}

console.log(formatNumber(60000, 3));
console.log(formatNumber(2529));

And use that formatNumber function for formatting.

Like, formatNumber(6000, 3) and it will return something like 60.000.

about 4 years ago · Santiago Trujillo Denunciar

0

You could take a function and convert the value to a sting, maintain the length and add a dot.

const
    format = integer => integer
        .toString()
        .padStart(3, 0)
        .replace(/(?=..$)/, '.');

console.log(format(0));
console.log(format(9));
console.log(format(19));
console.log(format(9959));

about 4 years ago · Santiago Trujillo 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