Number.prototype.toCurrency = function() { var cents, dollars, match, result; match = (this / 100).toString().match(/^-?(\d+)(\.\d+)?$/); if (!match) return; cents = match[2] ? (match[2] + '00').substr(1, 2) : '00'; dollars = match[1].replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1,'); result = "$" + dollars + "." + cents; if (this < 0) result = '-' + result; return result; };