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

407
Visualizações
Why do the numbers zero out after 49 digits after the decimal point?

I have been working on a program that approximates pi. It works just fine, but when I try to go any more that 49 digits after the decimal point, the next numbers zero out. I was wondering if this was maybe the equation that approximates pi, or if its javascript limiting the digits. Or maybe it could be my fault for coding it wrong. I just want to know what the problem is.

Heres the html and JavaScript code:

<button onclick="approximatePi()">
Approximate pi
</button>
<p id="t">

</p>
<script>
function approximatePi() {
//Get P element
  var t = document.getElementById("t")
 //For loop
  for (let i = 0; i < 2; i++) {
 //Variable for number close to pi.//
    var a = 3
 //Reiteration of equation a = a + sin(a) and display the value of a each iteration.
    for (let j = 0; j < 10; ++j) a = a + Math.sin(a);
    t.innerText = parseFloat(a).toPrecision(100) //toPrecision number set to 100 so you could see the zeros in the code output.
  }
  }
</script>

IMPORTANT NOTE: Ive tried changing the amount of iterations of the equation but it didnt seem to work. It just doesnt really want to display any more digits after 49 decimals after the point. Also im using jsfiddle if that helps.

about 4 years ago · Juan Pablo Isaza
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