functionword2number(w){ var e = "零一二三四五六七八九"; var ew = ["十","百","千"]; var ej = ["万","亿"]; var rss = "^(["+e+ew.join("")+"]+"+ej[1]+")?(["+e+ew.join("")+"]+"+ej[0]+")?(["+e+ew.join("")+"]+)?$"; // ^([零一二三四五六七八九十百千]+亿)?([零一二三四五六七八九十百千]+万)?([零一二三四五六七八九十百千]+)?$ var arr = newRegExp(rss).exec(w); functionfoh(str){ str = newString(str); var a=0; if(str.indexOf(ew[0])==0)a=10; str=str.replace(newRegExp(e.charAt(0),"g"),""); if(newRegExp("(["+e+"])$").test(str)) a+=e.indexOf(RegExp.$1); if(newRegExp("(["+e+"])"+ew[0]).test(str)) a+=e.indexOf(RegExp.$1)*10; if(newRegExp("(["+e+"])"+ew[1]).test(str)) a+=e.indexOf(RegExp.$1)*100; if(newRegExp("(["+e+"])"+ew[2]).test(str)) a+=e.indexOf(RegExp.$1)*1000; return a; } return foh(arr[1])*100000000+foh(arr[2])*10000+foh(arr[3]); }
//Test //==============
var str1 = "二十五"; var str2 = "五百零二"; var str3 = "四千五百"; var str4 = "七十亿零八百五十万四千五百零二";