ToPrecision-1

 

ToPrecision will format a number till provided length. In the below example it will return 33 because we provided 2 in toPrecision.

 
 
 
<!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 = 33.371; document.getElementById("sample").innerHTML = num.toPrecision(2); } </script> </body> </html>
Output