javascript 小写数字转换为汉字大写数字
function Chinese(num) { if(!/^/d*(/./d*)?$/.test(num)) throw(new Error(-1, "Number is wrong!")); var AA = new Array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖"); var BB = new Array("","拾","佰","仟","萬","億","圆",""); var CC = new A
function Chinese(num)
{
if(!/^/d*(/./d*)?$/.test(num)) throw(new Error(-1, "Number is wrong!"));
var AA = new Array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖");
var BB = new Array("","拾","佰","仟","萬","億","圆","");
var CC = new Array("角", "分", "厘");
var a = (""+ num).replace(/(^0*)/g, "").split("."), k = 0, re = "";
for(var i=a[0].length-1; i>=0; i--)
{
switch(k)
{
case 0 : re = BB[7] + re; break;
case 4 : if(!new RegExp("0{4}//d{"+ (a[0].length-i-1) +"}$").test(a[0]))
re = BB[4] + re; break;
case 8 : re = BB[5] + re; BB[7] = BB[5]; k = 0; break;
}
if(k%4 == 2 && a[0].charAt(i)=="0" && a[0].charAt(i+2) != "0") re = AA[0] + re;
if(a[0].charAt(i) != 0) re = AA[a[0].charAt(i)] + BB[k%4] + re; k++;
}
if(a.length>1) //加上小数部分(如果有小数部分)
{
re += BB[6];
上一篇: Java13 闪亮来袭,你是否还停留在 Java8
下一篇: 求知道的大大解释一下这里的引用
推荐阅读
-
自己实现string的substring方法 人民币小写转大写,数字反转,正则优化_javascript技巧
-
javascript 使用数组+循环+条件实现数字转换为汉字的简单方法。
-
大写字母或小写字母转换为数字
-
C# 字符串大写转小写,小写转大写,数字保留,其他除外
-
JS实现将数字金额转换为大写人民币汉字的方法
-
php小写数字转人民币大写数字的函数
-
自己实现string的substring方法 人民币小写转大写,数字反转,正则优化_javascript技巧
-
javascript 小写数字转换为汉字大写数字
-
JavaScript整数金额转汉语数字大写
-
JavaScript整数金额转汉语数字大写