Here you can find the source of toCurrency()
String.prototype.toCurrency = function() { /**//from w ww . j a va 2s .co m * Return a currency representation of a String. * e.g 11111.11 => 11,111.11 * Return NaN if the string is non-numerical. */ var isNumberRegex = /^[0-9]+(\.[0-9]+)?$/; if (!isNumberRegex.test(this)) { return NaN; } return parseFloat(Number(this).toFixed(2)) .toString() .replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,'); };
String.prototype.toCurrency = function() { var pattern = /^\d{4,}/; return pattern.test(this) ? parseFloat(this).toLocaleString() : this; };
String.prototype.toCurrency = function(){ var splitNum = this.split("."); var numCurrency = splitNum[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",") + ("." + splitNum[1]); return numCurrency; };
String.prototype.toCurrency = function() { var pattern = /(\d)(?=(\d{3})+(?=\.))/g return this.toString().replace(pattern, "$1,"); };
String.prototype.toCurrency = function(rounder) { aDigits = parseFloat(this).toFixed(rounder).split("."); aDigits[0] = aDigits[0].split("").reverse().join("") .replace(/(\d{3})(?=\d)/g, "$1,").split("").reverse().join(""); return aDigits.join(".");
String.prototype.toCurrency = function(rounder) { aDigits = parseFloat(this).toFixed(rounder).split("."); aDigits[0] = aDigits[0].split("").reverse().join("") .replace(/(\d{3})(?=\d)/g, "$1,").split("").reverse().join(""); return "Rp "+ aDigits.join(".");