The toFixed() function of the Number object accepts a number representing the number of points to be displayed after decimal and displays the current number accordingly.
Syntax
Its Syntax is as follows
num.toFixed(num);
Example
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<script type="text/javascript">
var num = Math.PI;
result = num.toFixed(4);
document.write("Fixed point notation of the given number is: " + result);
</script>
</body>
</html>Output
Fixed point notation of the given number is: 3.1416
Example
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<script type="text/javascript">
var num = Math.PI;
document.write("Fixed point notation of the given number is: " + num.toFixed(4));
document.write("<br>");
var num = 2.13e+15;
document.write("Fixed point notation of the given number is: " + num.toFixed(4));
</script>
</body>
</html>Output
Fixed point notation of the given number is: 3.1416 Fixed point notation of the given number is: 2130000000000000.0000