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

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

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 Relatório

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