- The toFixed() method converts a number into a string, keeping a specified number of decimals.
- If the desired number of decimals are higher than the actual number, nulls are added to create the desired decimal length.
Code:-
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- </head>
- <body>
- <h1>toFixed()</h1>
- <h2>77.366545</h2>
- <input type="button" onclick="fun_fxd();" value="toFixed(4)">
- <script>
- function fun_fxd()
- {
- var n1 = 77.366545;
- alert("Fixed: " + n1.toFixed(4));
- }
- </script>
- </body>
- </html>
The toFixed in JavaScript:- Geniusofstudent
Reviewed by Network security
on
July 02, 2019
Rating:
No comments: