The toFixed in JavaScript:- Geniusofstudent

  • 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:-


  1. <!DOCTYPE html> 
  2. <html> 
  3.  
  4. <head> 
  5.  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  6. </head> 
  7.  
  8. <body> 
  9.  <h1>toFixed()</h1> 
  10.  <h2>77.366545</h2> 
  11.  <input type="button" onclick="fun_fxd();" value="toFixed(4)"> 
  12.  
  13.  <script> 
  14.   function fun_fxd() 
  15.   { 
  16.    var n1 = 77.366545; 
  17.    alert("Fixed: " + n1.toFixed(4)); 
  18.   } 
  19.  </script> 
  20.  
  21. </body> 
  22.  
  23. </html>
The toFixed in JavaScript:- Geniusofstudent The toFixed in JavaScript:- Geniusofstudent Reviewed by Network security on July 02, 2019 Rating: 5

No comments:

Useful Information

Powered by Blogger.