Here you can find the source of toNumber()
String.prototype.toNumber = function(){ var str = this.gsub(",", "."); if (str.length == 0) return 0;// w w w. java 2 s .c om var parts = str.split("."); if (parts.length > 1){ var res = ''; for(var i=0; i<parts.length-1; i++){ res = res + parts[i]; } return parseFloat(res + '.' + parts[parts.length - 1]); } else return parseFloat(parts[0]); } String.prototype.isJSONDate = function(){ return /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).*Z$/.match(this); } String.prototype.toDate = function() { if (this.isJSONDate()){ return Date.fromJSON(this); } else{ return null; } } String.prototype.toCurrency = function(decimalPlaces){ return parseFloat(this).toCurrency(); }
String.prototype.toNum = function() { if (this.length === 0) return 0; return parseInt(this);
String.prototype.toNumber = function() { return parseInt(this); }; var ten = "10"; var fifty = "50"; console.log(ten.toNumber()); console.log(fifty.toNumber());
String.prototype.toNumber = function() { return parseFloat(this); };
String.prototype.toNumber = function(){ return +this; };
String.prototype.toNumber = function(){ if(this.match(/\./)){ return parseFloat(this, 10); } else { return parseInt(this, 10); };
String.prototype.toNumber = function() { return Number(this);
String.prototype.toNumber = function() var res = 0; for(var i = this.length - 1; i >= 0; --i) { res += res * 256 + this.charCodeAt( i ); return res;