示例:100转化为SAY ONE HUNDRED AND POINT ONLY
//数字金额转换英文大写(金额上线不能超过10亿)
var arr1=new Array(""," THOUSAND"," MILLION"," BILLION")
var arr2=new Array("ZERO","TEN","TWENT","THIRTY","FORTY","FIFTY","SIXTY","SEVENTY","EIGHTY","NINETY")
var arr3=new Array("ZERO","ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE");
var arr4=new Array("TEN","ELEVEN","TWELVE","THIRTEEN","FOURTEEN","FIFTEEN","SIXTEEN","SEVENTEEN","EIGHTEEN","NINETEEN");
//数字金额转换英文大写调这个方法
function englishmoney(money,currency){
var lstr = "", rstr = "";
if((money=='')||(money==null)) return('');
var z = money.indexOf("."); // 取小数点位置
var lstr = "", rstr = "";
if (z > -1) { // 看是否有小数,如果有,则分别取左边和右边
lstr = money.substring(0, z);
setlstr=convert(lstr);
rstr = money.substring(z + 1);
var len=rstr.length,i,j=0,strRet="";
var cols=Math.ceil(len/3);
var first=len-cols*3
var strRet=""
for(i=first;i<len;i+=3){
++j;
if(i>=0)
num3=rstr.substring(i,i+3)
else
num3=rstr.substring(0,first+3)
strEng=English(num3)
if(strEng!=""){
if(strRet!="") strRet+=","
strRet+=English(num3)+arr1[cols-j]
}
}
return "SAY "+currency+" "+setlstr+" AND POINT "+strRet+" ONLY";
} else// 否则就是全部
lstr=money;
return "SAY "+currency+" "+convert(lstr)+" ONLY";
}
//为了处理金额小数点前后 方法单独提出来了
function convert(num){
var len=num.length,i,j=0,strRet="";
var cols=Math.ceil(len/3);
var first=len-cols*3
var strRet=""
for(i=first;i<len;i+=3){
++j;
if(i>=0)
num3=num.substring(i,i+3)
else
num3=num.substring(0,first+3)
strEng=English(num3)
if(strEng!=""){
if(strRet!="") strRet+=","
strRet+=English(num3)+arr1[cols-j]
}
}
return strRet;
}
//在这里转换金额
function English(num){
strRet=""
if((num.length==3) && (num.substr(0,3)!="000")){
if((num.substr(0,1)!="0")){
strRet+=arr3[num.substr(0,1)]+" HUNDRED"
if(num.substr(1,2)!="00")strRet+=" AND "
}
num=num.substring(1);
}
if((num.length==2)){
if((num.substr(0,1)=="0")){
num=num.substring(1)
}
else if((num.substr(0,1)=="1")){
strRet+=arr4[num.substr(1,2)]
}
else{
strRet+=arr2[num.substr(0,1)]
if(num.substr(1,1)!="0")strRet+="-"
num=num.substring(1)
}
}
if((num.length==1) && (num.substr(0,1)!="0")){
strRet+=arr3[num.substr(0,1)]
}
return strRet;
}