CodesJava

Easy learning with example program codes

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>

Output

12.33
Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status