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

172
Visualizações
javascript percentage rounding

I have a value of 0.9019497053624151. It needs to display 90, so it is ideal to use the ff formula? by the way this is a percentage

console.log(Math.round(0.9019497053624151 * 10) / 10 * 100);

I tried rounding it off to 1 decimal place and then * 100, should I round it to 1 or 2 decimal places?

What do you call this percentage rounding? That from a value of 0.9019497053624151% the expected result is 90%

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Your question is 100% clear, but you should round it to 2 decimal places if you want only whole percents.

Also because you are using the round function, just multiply it by 100 (i.e. convert to percentage) and let it round to the nearest whole if that is what you are trying to accomplish.

console.log(Math.round(0.9019497053624151 * 100));

about 4 years ago · Juan Pablo Isaza Relatório

0

Are you trying to write precentage of random number or something like that?

Math.floor(Math.random() * 100) + 1 %

Math.random creates a float like [0,1[

Math.floor returns the largest integer less than or equal to a given number.

about 4 years ago · Juan Pablo Isaza Relatório

0

You can use the toFixed method (see documentation here)

You can specify the number of decimal you want. Example :

console.log(0.9119497053624151.toFixed(2));
console.log(0.9119497053624151.toFixed(4));
console.log(0.9119497053624151.toFixed(1));
console.log(0.9.toFixed(2));

You can then easely multiply it by 100 as you want :)

myNumber.toFixed(2) * 100

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