Node.js examples for String:Format
Add and remove comma from String
String.prototype.replaced = function (from, to) { var regular = new RegExp (from, "gi"); return this.replace (regular, to); } String.prototype.noCommas = function () { return this.replaced (",", ""); } Number.prototype.comma = function () { var to = ""; var from = String (this); if (from == "") return ""; else//from w w w . j a v a2s . c o m { while (from.length > 3) { to = "," + from.substr (from.length - 3, 3) + to; from = from.substr (0, from.length - 3); } return from + to; } }