# 自己写的一个大小写金额转化函数,贴出来大家看看

/*
* 输入为小写金额
* 函数已经在系统开发中的到使用,正确无误(一定条件下)
*/
public String DigitalConversion(String money)
{
String bigwrite="";
String midstr="";
String tempstr="";
int temp=0;
int view0=0;
String[] bigamount={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
String[] util={"分","角","圆","拾","佰","仟","万"};
String sStrmoney=DataFormat(money);
double amount=Double.parseDouble(sStrmoney);
int    number=(int)(amount*100.00);
while(number>0){
temp=number%10;
if(temp!=0)break;
number=number/10;
view0++;
}
if(view0==2) midstr+="整";
if(view0>2) midstr+="整圆";
temp=0;
while(number>0){
temp=number%10;
number=number/10;
view0++;
if(temp==0){tempstr="零";continue;}
midstr+=tempstr+util[view0-1]+bigamount[temp];
tempstr="";
}
for(int k=midstr.length()-1;k>=0;k--){
bigwrite+=midstr.substring(k,k+1);
}

return bigwrite;
}

<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
<body>
<script language="javascript">
function DataFormat(mon){
var monstr;
monstr = mon; //考虑到金额显示的问题大家可以在此函数中对初始金额作相应的处理比如，99，999.00-〉99999.00
return monstr;
}
function DigitalConversion(money) {
var bigwrite = "";
var midstr = "";
var tempstr = "";
var mtule = "";
var temp = 0;
var view0 = 0;
var flagi=false;
var flagj=false;
var bigamount = new Array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" );
var util = new Array("分", "角", "圆", "拾", "佰", "仟", "万", "拾", "佰", "仟","亿","拾","佰","仟" );
var sStrmoney = DataFormat(money);
var amount = sStrmoney;
var number = amount * 100.00;
var snumber = number+"";
var len = snumber.length;
if(number % 100000 == 0){
flagi=true;
}
if(number % 10000000000 == 0){
flagj=true;
flagi=false;
}
var div =  10;
while (number > 0) {
temp = number % div;
if (temp != 0)
break;
number = number / 10;
view0++;
}
if (view0 == 2)
midstr += "整";
if (view0 > 2)
midstr += "整圆";
temp = 0;
if(flagi==true){
midstr+="万";
}
if(flagj==true){
midstr+="亿";
}
while (number > 0) {
temp = Math.round(number % 10);
number = Math.floor(number / 10);
view0++;
if(view0 == 3 && temp == 0){
mtule = "圆";
}
if (view0 == 7 && temp == 0) {
mtule = "万";
}
if (view0 == 11 && temp == 0) {
mtule = "亿";
}
if (temp == 0) {
tempstr = "零";
continue;
}
midstr += tempstr + mtule + util[view0 - 1] + bigamount[temp];
tempstr = "";
mtule = "";
}
for (k = midstr.length - 1; k >= 0; k--) {
bigwrite += midstr.charAt(k);
}
if(len == 8 || len == 12){
if (snumber.charAt(0)=='1') {
bigwrite = bigwrite.substring(1, bigwrite.length);
}
}
bigwrite=bigwrite.replace("万万","万");
bigwrite=bigwrite.replace("亿亿","亿");
return bigwrite;
}
function chg(){
document.all.view.value=DigitalConversion(document.all.mon.value);
}
</script>
<input type="text" name="mon" /><br/>
<input name="view" type="text" size="100" maxlength="600"/>
<br/>
<input type="button" value="kaishi" onclick="chg()"/>
</body>
</html>
• 本文已收录于以下专栏：

举报原因： 您举报文章：自己写的一个大小写金额转化函数,贴出来大家看看 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)