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

251
Visualizações
How to convert a floating number to fixed floating number using JavaScript

For example, I want to calculate 3/6. 3/6 answer is a 0.5 floating number. When I fixed this number with the javascript toFixed(6) method it returned '0.500000'. The problem is that '0.500000' is a string. But I want a floating number with 6 digits after the dot(.). How can I do that? I tried this but it's won't work.

parseFloat((3/6).toFixed(6))
//output = 0.5 but i want 0.500000
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Well,

parseFloat((3/6).toFixed(6))
//output = 0.5 means everything after .5 is 0

If you print it to the console it will remove the unnecessary zero. When you need to print up to 5 or 10 decimal points, you have to convert the number into a string using the toFixed method.

about 4 years ago · Juan Pablo Isaza Relatório

0

Why are you using toFixed inside the parseFloat() because of that it is returning you 0.5

Do this

let a = parseFloat((3/6).toFixed(6))
console.log(a)
about 4 years ago · Juan Pablo Isaza Relatório

0

I updated my answer. I did not get that you wanted to use the output as a number. I don't think that what you want to achieve is possible. It's possible only if you keep you value as a string.

const numb = 3/6;
console.log(numb.toFixed(6));

For documentation: https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed

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