Javascript money format

Number.prototype.moneyformat = function(decPlaces, thouSeparator, decSeparator) {
	var n = this,
	sign = n < 0 ? "-" : "",
	i = parseInt(n = Math.abs(+n || 0).toFixed(decPlaces),10) + "",
	j = (j = i.length) > 3 ? j % 3 : 0;
	return sign + (j ? i.substr(0, j) + thouSeparator : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thouSeparator) + (decPlaces ? decSeparator + Math.abs(n - i).toFixed(decPlaces).slice(2) : "");
};

usage:

var myMoney=3543.75873;
var formatedMoney = myMoney.moneyformat(2,'.',',') + ' EUR';

Archive for May, 2013

Archives by Month: