Skip to content

JavaScript toPrecision() function | Number to a specified precision

  • by

JavaScript toPrecision() function is used to format a number to a specified length. This method returns a string representing the Number object to the specified precision.

number.toPrecision(x)

Number object to specified precision with JavaScript toPrecision()

Simple example code format a number to a specified length.

<!DOCTYPE html>
<html>
<head>

  <script>
    let num = 13.3714;
    let n = num.toPrecision(4);

    console.log(n); 
  </script>
</head>
<body>

</body>
</html>

Output:

JavaScript toPrecision() function

Do comment if you have any doubts or suggestions on this JS precision function.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading