金额小写变成大写代码
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 5 <title>无标题文档</title> 6 <script language="javascript"> 7 <!-- 8 function Arabia_to_Chinese(number) 9 { 10 var i = 0; 11 var Num = number.toString(); 12 for(i=Num.length-1;i>=0;i--) 13 { 14 Num = Num.replace(",","")//替换tomoney()中的“,” 15 Num = Num.replace(" ","")//替换tomoney()中的空格 16 } 17 Num = Num.replace("¥","")//替换掉可能出现的¥字符 18 if(isNaN(Num)) 19 {//验证输入的字符是否为数字 20 alert("请检查小写金额是否正确"); 21 return; 22 } 23 //---字符处理完毕,开始转换,转换采用前后两部分分别转换---// 24 Num = Num.replace(".","点") 25 var part = Num.split("点"); 26 var newchar = ""; 27 //小数点前进行转化 28 var perchar = 0; 29 var tmpnewchar = ""; 30 for(i = 0;i < part[0].length;i++) 31 { 32 if(part[0].length > 10) 33 { 34 alert("位数过大,无法计算");return ""; 35 }//若数量超过拾亿单位,提示 36 perchar = part[0].charAt(i); 37 switch(perchar) 38 { 39 case "0": 40 tmpnewchar="零"; 41 document.write(tmpnewchar); 42 break; 43 case "1": 44 tmpnewchar="壹"; 45 document.write(tmpnewchar); 46 break; 47 case "2": 48 tmpnewchar="贰"; 49 document.write(tmpnewchar); 50 break; 51 } 52 } 53 document.write("点"); 54 document.write(part[1]); 55 } 56 --> 57 </script> 58 </head> 59 <body> 60 61 <script language="javascript"> 62 Arabia_to_Chinese(10.01); 63 </script> 64 </body> 65 </html>