String.prototype.number_format = function(decimals,dec_point,thousands_sep){
	if(decimals==null){decimals=999;}	
	if(dec_point==null){dec_point='.';}if(thousands_sep==null){thousands_sep=',';}
	var arr = this.toString().replace(/[^-\.\+\d]/g,'').split(dec_point);
	if(arr[1] && arr[1].length>0){arr[1] = arr[1].substr(0,decimals);}
	arr[0] = arr[0].replace(/(\d)(?=(?:\d{3})+(?!\d))/g,'$1'+thousands_sep);
	if(arr[1] && decimals>0 && arr[1].length>0){return arr[0] + dec_point + arr[1];}
	else {return arr[0];}
}
Number.prototype.number_format = function(decimals,dec_point,thousands_sep){
	return this.toString().number_format(decimals,dec_point,thousands_sep)
}
function number_format(num){document.write(num.number_format());}