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.