Convert String to Float up to 2 Decimal places - Javascript String Operation

Javascript examples for String Operation:String Convert

Description

Convert String to Float up to 2 Decimal places

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(){/*ww  w  .  j a v  a 2 s.c  om*/
Number.prototype.toString = function(){
   return this.toFixed(2);
}
var oneone = new Number( 1.1 );
// since implicit conversion to string is required it will show 1.10
console.log( oneone );
    }

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

Related Tutorials