日期:2014-05-16  浏览次数:20406 次

js数字转换成大写人民币

function FMchange(value,item) {
?//var money=document.all.Fld_totalMoney.value; 万元
?value=parseFloat(value,10)
?value=value.toString()
?var value1;
?var number="零,壹, 贰, 叁, 肆, 伍, 陆, 柒, 捌, 玖";
?var na=number.split(",");
?var hou="";
?if(value.indexOf(".")>-1) {
? value1=value.substring(0,value.indexOf("."));
? var type2="角,分".split(",");
? var value2=value.substring(value.indexOf(".")+1,value.indexOf(".")+3);
? for(var f=0;f<value2.length;f++) {
?? hou=hou+na[value2.charAt(f)]+type2[f]
? }
? hou=hou.replace("零角","零").replace("零分","零").replace("零零","");
?}else {
? value1=value;
?}
?var money=value1;
?var type="圆,万,亿,万亿";
?var ta=type.split(",");
?var shu=",拾,佰,仟";
?var sa=shu.split(",");
?var len=money.length;
?var l=parseInt(len/4);
?var re="";
?if(len>16) {
? alert("数据超过了转换范围,请手写输入!");
? return false;
?}
?if(len%4>0) {
? for(var k=0;k<len%4;k++) {
?? var g=len%4-1-k;
?? re=re+na[money.charAt(k)]+sa[g];
? }
? re=re+ta[l];
?}
?for(var i=l;i>0;i--) {
? var t;
? t=0;
? for(var j=len-4*i;j<len-4*i+4;j++) {
?? g=3-t;
?? //alert(na[money.charAt(j)]);
?? re=re+na[money.charAt(j)]+sa[g]
?? t=t+1;
? }
? re=re+ta[i-1];
?}
?for(var q=0;q<5;q++) {
? re=re.replace("零仟","零").replace("零佰","零").replace("零拾","零").replace("零圆","圆零").replace(/零+/g,"零").replace(/^圆/,"");
?re=re.replace(/^壹拾/,"拾").replace(/^零/,"");
? re=re.replace("亿亿","亿").replace("零亿","亿").replace("零万","万").replace("亿万","亿");
?}
?//re=re+hou+"整";
?if (hou != ""){
?re=re+hou;
?}else? if(re != ""){
?re=re.replace(/零$/,"");
? re=re+"整";
?}
?re=re.replace(/\s/g,"");

?if(value=='NaN'){
?re='';
?}
?document.all(item).value=re;
}

?

?

转载http://czs0061983.blog.163.com/blog/static/408171120106236540968/