<script language="JavaScript">
<!--
/*作者:梅雪香 Meixx (code by meixx 2006-2-15)
*功能:把16位以内整数转换成大写中文
*使用方法: num.parseCN()
*问题:当数值大于9999,9999,9999,9990的时候显示不准确,为9999,9999,9999,9999时,提示错误.
*/
Number.prototype.parseCN = function(){
//参数检查
if(/\./g.test(this.toString()) || Math.abs(this).toString().length >16 )
throw new Error(-1,"Number.parseCN()的参数非法!");
var strResult = this<0?"负":"";
var num = Math.abs(this);
var numArr = num.split();
var strSys = "万亿兆";
var len = numArr.length;
for(var i=len-1;i>=0;i--){
var n = numArr[i];
var ch = strSys.charAt(i-1);
strResult += (/^0{4}$/.test(n)?"":(n.read() +(ch?ch:"")));
}
return strResult;
}
Number.prototype.split = function (){
var str = this.toString();
var arr = new Array();
var len = str.length;
for(var i=0,j=len/4;i<j;i++)
arr.push(str.substring(len-4*(i+1),len-4*i));
return arr;
}
String.prototype.read = function(){
var strChNum = "零壹贰叁肆伍陆柒捌玖";
var strUnit = "拾佰仟";
var strRtn = "";
var len = this.length;
var isZeroPre = false;
var isNonZeroAppear = false;
for(var i=len-1;i>=0;i--){
if(this.charAt(i) != "0"){
strRtn = strChNum.charAt(this.charAt(i)) +
(strUnit.charAt(len-2-i)?strUnit.charAt(len-2-i):"") +
(isZeroPre?"零":"") + strRtn;
isNonZeroAppear = true;
isZeroPre = false;
}
else{
isZeroPre = isNonZeroAppear;
if(i == 0 ) strRtn = "零" + strRtn;
}
}
return strRtn;
}
var i=9999999999999990
document.write( i.parseCN() + "<br/>");
//for(var i=9898;i<11111;i++)
//document.write( i.parseCN() + "<br/>");
//-->
</script>
posted on 2006-04-03 14:33
汪杰 阅读(161)
评论(0) 编辑 收藏 引用 所属分类:
hengxing网站js