function numberFormat() {
	
}
numberFormat.prototype={
	 noFormat: function(value) {
		return ''+value
	}
	,doFormat: function(value) {
		var multiplier=this._multiplier;
		var abs=(value<0)?-value:value;
		var delta=(value<0)?-0.5:+0.5;
		var rounded=(Math.round(value * multiplier)+delta)/multiplier+"";
		if (abs<1000) {
			return this.rs+rounded.replace(this.p1,this.r1)+this.re
		}
		if (abs<1000000) {
			return this.rs+rounded.replace(this.p2,this.r2)+this.re
		}
		if (abs<1000000000) {
			return this.rs+rounded.replace(this.p3,this.r3)+this.re
		}
		if (abs<1000000000000) {
			return this.rs+rounded.replace(this.p4,this.r4)+this.re
		}
		return this.rs+rounded.replace(this.p5,this.r5)+this.re
	}
	,setNumberFormat: function(format) {
		var pattern=/^([^0#]*)([0#]*)([ .,]?)([0#]|[0#]{3})([.,])([0#]*)([^0#]*)$/;
		var f=format.match(pattern);
		if(!f) {
			this.valueToText=this.noFormat;
			return
		}
		this.valueToText=this.doFormat;
		this.rs=f[1];
		var rg=f[3];
		var rd=f[5];
		this.dot=rd;
		this.re=f[7];
		var decimals=f[6].length;
		this._multiplier=Math.pow(10,decimals);
		var ps="^(-?\\d+)",pm="(\\d{3})",pe="\\.(\\d{"+decimals+"})\\d$";
		this.p1=new RegExp(ps+pe);
		this.p2=new RegExp(ps+pm+pe);
		this.p3=new RegExp(ps+pm+pm+pe);
		this.p4=new RegExp(ps+pm+pm+pm+pe);
		this.p5=new RegExp(ps+pm+pm+pm+pm+pe);
		if (decimals) {
			this.r1="$1"+rd+"$2";
			this.r2="$1"+rg+"$2"+rd+"$3";
			this.r3="$1"+rg+"$2"+rg+"$3"+rd+"$4";
			this.r4="$1"+rg+"$2"+rg+"$3"+rg+"$4"+rd+"$5";
			this.r5="$1"+rg+"$2"+rg+"$3"+rg+"$4"+rg+"$5"+rd+"$6";
		} else {
			this.r1="$1";
			this.r2="$1"+rg+"$2";
			this.r3="$1"+rg+"$2"+rg+"$3";
			this.r4="$1"+rg+"$2"+rg+"$3"+rg+"$4";
			this.r5="$1"+rg+"$2"+rg+"$3"+rg+"$4"+rg+"$5";
		}
	}
	,textToValue: function (data) {
		data=data+'';
		data=data.replace(/[^0-9\\,.]+/g, '');
		data=data.replace(/[\\.,]/g, '.');
		data=data.replace(/[^0-9]+(?=[0-9]+\.)/g, '');
		if (data=='') return 0;
		return Number(data);
	}
}
function getNumberFormat(num, format) {
	var nf=new numberFormat();
	nf.setNumberFormat(format);
	return nf.valueToText(num);
}
