Nodejs String to Number Convert toNumber()

Here you can find the source of toNumber()

Method Source Code

String.prototype.toNumber = function()
{
   var res = 0;/*from  ww w. j av a 2 s. c om*/

   for(var i = this.length - 1; i >= 0; --i) {
      res += res * 256 + this.charCodeAt( i );
   }

   return res;
}

Related

  1. toNumber()
    String.prototype.toNumber = function() {
      return parseFloat(this);
    };
    
  2. toNumber()
    String.prototype.toNumber = function(){
      return +this;
    };
    
  3. toNumber()
    String.prototype.toNumber = function(){
      if(this.match(/\./)){
        return parseFloat(this, 10);
      } else {
        return parseInt(this, 10);
    };
    
  4. toNumber()
    String.prototype.toNumber = function(){
      var str = this.gsub(",", ".");
      if (str.length == 0)
        return 0;
      var parts = str.split(".");
      if (parts.length > 1){               
        var res = '';
        for(var i=0; i<parts.length-1; i++){
          res = res + parts[i];
    ...
    
  5. toNumber()
    String.prototype.toNumber = function() {
        return Number(this);