LearningJS
LearningJS copied to clipboard
toFixed rounding
Correct me if I'm wrong, but toFixed() is a rounding method, correct? I'm just wondering if this would be the best solution to this problem.
I could be wrong, so feel free to correct me. I'm just a beginner. Thanks.
You're actually right, from the instruction, the idea is to input a number and have your program generate Pi to 'THAT' number of decimal places. Anyway I think you could handle the solution like the code below (just copy, paste and run on your browser with a .html file);
ENTER THE NUMBER OF DECIMAL PLACES PI IS TO BE CALCULATED TO:  
<input type="number" name="txtbox" id="val" value="">
<input type="submit" onclick = "nth()">
<br/>
<script>
function nth() {
var nthval = document.getElementById("val").value;
var pival = (3.141592653589793238462643383279 + Math.sin (3.141592653589793238462643383279));
var pinth = pival.toFixed(nthval);
document.getElementById("demo").innerHTML = pinth;
}
</script>
<h2><p id="demo"></p></h2>
</body>
_______________________________________________________________
Hope this is in line with what you were thinking...