Number.formatFunctions={count:0};Number.prototype.NaN="NaN";Number.prototype.posInfinity="Infinity";Number.prototype.negInfinity="-Infinity";Number.prototype.numberFormat=function(a,b){if(isNaN(this))return Number.prototype.NaNstring;else if(this==Infinity)return Number.prototype.posInfinity;else if(this==-Infinity)return Number.prototype.negInfinity;else Number.formatFunctions[a]==null&&Number.createNewFormat(a);return this[Number.formatFunctions[a]](b)};
Number.createNewFormat=function(a){var b="format"+Number.formatFunctions.count++;Number.formatFunctions[a]=b;var b="Number.prototype."+b+" = function(context){\n",c=a.split(";");switch(c.length){case 1:b+=Number.createTerminalFormat(a);break;case 2:b+='return (this < 0) ? this.numberFormat("'+String.escape(c[1])+'", 1) : this.numberFormat("'+String.escape(c[0])+'", 2);';break;case 3:b+='return (this < 0) ? this.numberFormat("'+String.escape(c[1])+'", 1) : ((this == 0) ? this.numberFormat("'+String.escape(c[2])+
'", 2) : this.numberFormat("'+String.escape(c[0])+'", 3));';break;default:b+="throw 'Too many semicolons in format string';"}eval(b+"}")};
Number.createTerminalFormat=function(a){if(a.length>0&&a.search(/[0#?]/)==-1)return"return '"+String.escape(a)+"';\n";var b="var val = (context == null) ? new Number(this) : Math.abs(this);\n",c=!1,e=a,h="",d=0,f=0,i=0,j=!1,k="";if(g=a.match(/\..*(e)([+-]?)(0+)/i))k=g[1],j=g[2]=="+",i=g[3].length,a=a.replace(/(e)([+-]?)(0+)/i,"");var g=a.match(/^([^.]*)\.(.*)$/);g&&(e=g[1].replace(/\./g,""),h=g[2].replace(/\./g,""));a.indexOf("%")>=0&&(b+="val *= 100;\n");(g=e.match(/(,+)(?:$|[^0#?,])/))&&(b+="val /= "+
Math.pow(1E3,g[1].length)+"\n;");e.search(/[0#?],[0#?]/)>=0&&(c=!0);if(g||c)e=e.replace(/,/g,"");if(g=e.match(/0[0#?]*/))d=g[0].length;if(g=h.match(/[0#?]*/))f=g[0].length;i>0?b+="var sci = Number.toScientific(val,"+d+", "+f+", "+i+", "+j+");\nvar arr = [sci.l, sci.r];\n":(a.indexOf(".")<0&&(b+="val = (val > 0) ? Math.ceil(val) : Math.floor(val);\n"),b+="var arr = val.round("+f+").toFixed("+f+").split('.');\n",b+="arr[0] = (val < 0 ? '-' : '') + String.leftPad((val < 0 ? arr[0].substring(1) : arr[0]), "+
d+", '0');\n");c&&(b+="arr[0] = Number.addSeparators(arr[0]);\n");b+="arr[0] = Number.injectIntoFormat(arr[0].reverse(), '"+String.escape(e.reverse())+"', true).reverse();\n";f>0&&(b+="arr[1] = Number.injectIntoFormat(arr[1], '"+String.escape(h)+"', false);\n");i>0&&(b+="arr[1] = arr[1].replace(/(\\d{"+f+"})/, '$1"+k+"' + sci.s);\n");return b+"return arr.join('.');\n"};
Number.toScientific=function(a,b,c,e,h){var d={l:"",r:"",s:""},f="",i=Math.abs(a).toFixed(b+c+1).trim("0"),c=Math.round(new Number(i.replace(".","").replace(RegExp("(\\d{"+(b+c)+"})(.*)"),"$1.$2"))).toFixed(0);c.length>=b?c=c.substring(0,b)+"."+c.substring(b):c+=".";d.s=i.indexOf(".")-i.search(/[1-9]/)-c.indexOf(".");d.s<0&&d.s++;d.l=(a<0?"-":"")+String.leftPad(c.substring(0,c.indexOf(".")),b,"0");d.r=c.substring(c.indexOf(".")+1);d.s<0?f="-":h&&(f="+");d.s=f+String.leftPad(Math.abs(d.s).toFixed(0),
e,"0");return d};Number.prototype.round=function(a){if(a>0){var b=this.toFixed(a+1).match(RegExp("(-?\\d*).(\\d{"+a+"})(\\d)\\d*$"));if(b&&b.length)return new Number(b[1]+"."+String.leftPad(Math.round(b[2]+"."+b[3]),a,"0"))}return this};
Number.injectIntoFormat=function(a,b,c){var e=0,h=0,d="",f=a.charAt(a.length-1)=="-";for(f&&(a=a.substring(0,a.length-1));e<b.length&&h<a.length&&b.substring(e).search(/[0#?]/)>=0;)b.charAt(e).match(/[0#?]/)?(d+=a.charAt(h)!="-"?a.charAt(h):"0",h++):d+=b.charAt(e),++e;f&&h==a.length&&(d+="-");h<a.length&&(c&&(d+=a.substring(h)),f&&(d+="-"));e<b.length&&(d+=b.substring(e));return d.replace(/#/g,"").replace(/\?/g," ")};
Number.addSeparators=function(a){return a.reverse().replace(/(\d{3})/g,"$1,").reverse().replace(/^(-)?,/,"$1")};String.prototype.reverse=function(){for(var a="",b=this.length;b>0;--b)a+=this.charAt(b-1);return a};String.prototype.trim=function(a){a||(a=" ");return this.replace(RegExp("^"+a+"+|"+a+"+$","g"),"")};String.leftPad=function(a,b,c){a=new String(a);for(c==null&&(c=" ");a.length<b;)a=c+a;return a};String.escape=function(a){return a.replace(/('|\\)/g,"\\$1")};

