JavaScript Number toPrecision() method

The JavaScript number toPrecision() method is used to get the string representing a number of specified precision or length. Syntax: Number.toPrecision(n) Parameters n: It represents the total number of digits. Returns String representation of a number of specified precision. Example: <!DOCTYPE html> <html> <body> <script> var n= 12.334; document.writeln(n.toPrecision(4)); </script> </body> </html>