阿拉伯数字123456789转为 ,财务数字零壹贰叁肆伍陆柒捌玖。

代码如下:

 


 

function toChinaNumber (options) {
options=options+
"";
options = options.replace(/^0+/, "");
var
numberAry = ["","","","","","","","","",""],
unitAry = ["","","",""],
bigUnitAry = ["","","亿"];
var
targetStr = "";
var
zeroFlag = 0;
var
i, p, nowAloneNumber;
var
quotient, modulus;
var
len=options.length;
if
(len==0){
targetStr +=
"";
}else{
for (i = 0; i < len; i++) {
p = len - i -
1;
nowAloneNumber = options.substr(i, 1);
quotient = p / 4;//
modulus = p % 4;//余数
if (nowAloneNumber == "0") {
zeroFlag++
;
} else {
if (zeroFlag > 0) {
targetStr += numberAry[
0];
}
zeroFlag =
0;
targetStr += numberAry[Number(nowAloneNumber)] + unitAry[modulus];
}
if (modulus == 0 && zeroFlag < 4) {
targetStr += bigUnitAry[quotient]
;
zeroFlag = 0;
}
}
}
targetStr +=
"元整";
return
targetStr;
}

var testNumber=35987;
var
testStr="298";
console
.log(toChinaNumber(testNumber));
console
.log(toChinaNumber(testStr));