ToPrecision-2

 

ToPrecision will retun different result based on provided length.

 
 
 
<!DOCTYPE html> <html> <head> <title>Welcome to LearnKode - A code learning platform</title> </head> <body> <button onclick="convertToPrecision()">Display the formatted number</button> <p id="sample"></p> <script> function convertToPrecision() { 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("sample").innerHTML = n; } </script> </body> </html>
Output