js汉字转换为阿拉伯数字  直接贴函数

function cnnumtonum(chnStr){
var chnNumChar = {
零:,一:,二:,三:,四:,五:,六:,七:,八:,九:
};
var chnNameValue = {
十:{value:, secUnit:false},
百:{value:, secUnit:false},
千:{value:, secUnit:false},
万:{value:, secUnit:true},
亿:{value:, secUnit:true}
};

var expNumChar= {
十:10,十一:11,十二:12,十三:13,十四:14,十五:15,十六:16,十七:17,十八:18,十九:19
};
if(expNumChar[chnStr]) {
return expNumChar[chnStr];
}

var rtn = ;
var section = ;
var number = ;
var secUnit = false;
var str = chnStr.split('');
for(var i = ; i < str.length; i++){
var num = chnNumChar[str[i]];
if(typeof num !== 'undefined'){
number = num;
if(i === str.length - ){
section += number;
}
}else{

var cunit = chnNameValue[str[i]];

if(typeof cunit == 'undefined') {
return false;
}

var unit = chnNameValue[str[i]].value;
secUnit = chnNameValue[str[i]].secUnit;
if(secUnit){
section = (section + number) * unit;
rtn += section;
section = ;
}else{
section += (number * unit);
}
number = ;
}
}
return rtn + section;
} var chnStr='一百零九';
var aa=cnnumtonum(chnStr);
console.log(aa);

阿拉伯数字转汉字

function numtocnnum(section) {
var chnNumChar = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
var chnUnitSection = ["", "万", "亿", "万亿", "亿亿"];
var chnUnitChar = ["", "十", "百", "千"];
var strIns = '', chnStr = '';
var unitPos = ;
var zero = true;
while (section > ) {
var v = section % ;
if (v === ) {
if (!zero) {
zero = true;
chnStr = chnNumChar[v] + chnStr;
}
} else {
zero = false;
strIns = chnNumChar[v];
strIns += chnUnitChar[unitPos];
chnStr = strIns + chnStr;
}
unitPos++;
section = Math.floor(section / );
}
return chnStr;
}
var chnStr='';
var aa=numtocnnum(chnStr);
console.log(aa);
05-16 15:46