Parse String to float and format with two decimal - Javascript String Operation

Javascript examples for String Operation:String Parse

Description

Parse String to float and format with two decimal

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from ww w  . ja v  a 2s  . co  m

function roundNumber() {
  let myNumber = '0.256789';
  return parseFloat(myNumber).toFixed(2);
}
document.write(roundNumber());


    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials