(
function
(s)
...
{
s.toFixed = function(n)...{
with(Math)return round(Number(this)*pow(10,n))/pow(10,n)
}
s.hex = function()...{
s.toFixed = function(n)...{
with(Math)return round(Number(this)*pow(10,n))/pow(10,n)
}
s.hex = function()...{
var s = this.toString(16),len = s.indexOf(".");
if(len == -1)len = s.length;
return len%2 == 0?s:"0"+s;
}
s.equals = s.equalsV = function(other)...{
return this == other;
}
s.toJSONString = function()...{
return isFinite(this)?String(this):"null";
}
s.color = function()...{
var s = this.toString(16).array(),l = s.length,_="0";
if(this >=0 && l <7)...{
var r = l >1?["#",_,_,_,_,_,_]:["#",_,s[0]||_,_,_,_,_];
for(var i=l;i>0;i -=2)...{
r[l-i+1] = s[i-2]||_;
r[l-i+2] = s[i-1]||_;
}
return r.join("");
}else return "#";
}
s.cn = function(z)...{
var m = ["零","壹","贰","叁","肆","伍","陆","柒","捌","玖","点","整","负"];
var p = ["","拾","佰","仟"],q = ["",“万","亿","兆"],b=["元","角","分"];
var pi = qi = 0;r = []; s= Math.abs(this), f= s- Math.floor(s),l = 0;
while(s > 0){
if(pi>3){
pi = 0;
qi ++;
if(qi > 3) qi = 1;
r.unshift(q[qi]);
}
var x = Math.floor(s%10);
if(!z){
if( x!= 0)r.unshift(m[x],p[pi]);
else if(l!=0 && q.all(function(o){return r[0] != o},1))r.unshift(m[0]);
l=x;
}else r.unshift(m[x],p[pi]);
s = Math.floor(s/10);
pi++;
}
if(f!=0){
l=0;
var is$= z == "$",maxl = is$?2:7;
is$?r.push(b[l]):r.push(m[10]);
while( f!=0 && l<maxl){
x = l == maxl-1?Math.round(f*10):Math.floor(f*10);
if(x ==10){
x = 0;
(function(len){
var _q = function(o){return r[len] ===o};
if(b.any(_q)|| q.any(-_q)||p.any(_q)|| b==m[10])arguments.callee(len-1);
var tx = m.indexOf(r[len]);
if(tx !=-1){
tx ++;
if(tx ==10){
tx = 0;
arguments.callee(len-1);
}
}
})(r.length-1);
}
r.push(m[x]);
f = f*10-Math.floor(f*10);
l++;
!is$ || r.push(b[l]||"");
}
(function(){x=r.last();if(x==m[0] || x===""){r.pop();arguments.callee()}})();
}else !is$||r.push(b[0]);
!is$ || r.push(m[11]);
this>=0 ||r.unshift(m[12]);
r= r.join("").replace(/(兆|亿)(亿|万)+/g,"$1").replace(/零(角|分)/g,"");
return this==0?m[0]:r;
}
})(Number.prototype)
return len%2 == 0?s:"0"+s;
}
s.equals = s.equalsV = function(other)...{
return this == other;
}
s.toJSONString = function()...{
return isFinite(this)?String(this):"null";
}
s.color = function()...{
var s = this.toString(16).array(),l = s.length,_="0";
if(this >=0 && l <7)...{
var r = l >1?["#",_,_,_,_,_,_]:["#",_,s[0]||_,_,_,_,_];
for(var i=l;i>0;i -=2)...{
r[l-i+1] = s[i-2]||_;
r[l-i+2] = s[i-1]||_;
}
return r.join("");
}else return "#";
}
s.cn = function(z)...{
var m = ["零","壹","贰","叁","肆","伍","陆","柒","捌","玖","点","整","负"];
var p = ["","拾","佰","仟"],q = ["",“万","亿","兆"],b=["元","角","分"];
var pi = qi = 0;r = []; s= Math.abs(this), f= s- Math.floor(s),l = 0;
while(s > 0){
if(pi>3){
pi = 0;
qi ++;
if(qi > 3) qi = 1;
r.unshift(q[qi]);
}
var x = Math.floor(s%10);
if(!z){
if( x!= 0)r.unshift(m[x],p[pi]);
else if(l!=0 && q.all(function(o){return r[0] != o},1))r.unshift(m[0]);
l=x;
}else r.unshift(m[x],p[pi]);
s = Math.floor(s/10);
pi++;
}
if(f!=0){
l=0;
var is$= z == "$",maxl = is$?2:7;
is$?r.push(b[l]):r.push(m[10]);
while( f!=0 && l<maxl){
x = l == maxl-1?Math.round(f*10):Math.floor(f*10);
if(x ==10){
x = 0;
(function(len){
var _q = function(o){return r[len] ===o};
if(b.any(_q)|| q.any(-_q)||p.any(_q)|| b==m[10])arguments.callee(len-1);
var tx = m.indexOf(r[len]);
if(tx !=-1){
tx ++;
if(tx ==10){
tx = 0;
arguments.callee(len-1);
}
}
})(r.length-1);
}
r.push(m[x]);
f = f*10-Math.floor(f*10);
l++;
!is$ || r.push(b[l]||"");
}
(function(){x=r.last();if(x==m[0] || x===""){r.pop();arguments.callee()}})();
}else !is$||r.push(b[0]);
!is$ || r.push(m[11]);
this>=0 ||r.unshift(m[12]);
r= r.join("").replace(/(兆|亿)(亿|万)+/g,"$1").replace(/零(角|分)/g,"");
return this==0?m[0]:r;
}
})(Number.prototype)
1、toFixed
按四舍五入的规则保留n位小数。
2、hex
返回16进制字符串。
3、equals、equalsV
为对象的比较准备的基础方法之一。
4、color
将一个整数转换为颜色RGB字符串。
6、cn
将一个数字转换为中文或人民币中文数字(可供发票打印用)。
参数:无参数时,转换为中文读法:100024.21返回壹拾万零贰拾肆点贰壹。
参数为true时,转换为中文读法,但不省略中间的零。100024.21返回壹拾零万零仟零佰贰拾肆点贰壹。
参数为"$"时,返回人民币中文数字100024.21返回壹拾零万零仟零佰贰拾肆元贰角壹分整。