Javascript examples for Number:toPrecision
Format a number to a specified length:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*from w ww. j a v a2 s. co m*/ var num = 13.3714; var a = num.toPrecision(); var b = num.toPrecision(2); var c = num.toPrecision(3); var d = num.toPrecision(10); var n = a + "<br>" + b + "<br>" + c + "<br>" + d; document.getElementById("demo").innerHTML = n; } </script> </body> </html>