分类:
2008-09-09 16:59:47
从CSDN上整理出五个方案:
1、(JAVA)
public static String numtochinese(String input){
String s1="零壹贰叁肆伍陆柒捌玖";
String s4="分角整元拾佰仟万拾佰仟亿拾佰仟";
String temp="";
String result="";
if (input==null) return "输入字串不是数字串只能包括以下字符(′0′~′9′,′.′),输入字串最大只能精确到仟亿,小数点只能两位!";
temp=input.trim();
float f;
try{
f=Float.parseFloat(temp);
}catch(Exception e){return "输入字串不是数字串只能包括以下字符(′0′~′9′,′.′),输入字串最大只能精确到仟亿,小数点只能两位!";}
int len=0;
if (temp.indexOf(".")==-1) len=temp.length();
else len=temp.indexOf(".");
if(len>s4.length()-3) return("输入字串最大只能精确到仟亿,小数点只能两位!");
int n1,n2=0;
String num="";
String unit="";
for(int i=0;iif(i>len+2){break;}
if(i==len) {continue;}
n1=Integer.parseInt(String.valueOf(temp.charAt(i)));
num=s1.substring(n1,n1+1);
n1=len-i+2;
unit=s4.substring(n1,n1+1);
result=result.concat(num).concat(unit);
}
if ((len==temp.length()) | |(len==temp.length()-1)) result=result.concat("整");
if (len==temp.length()-2) result=result.concat("零分");
return result;
}
2、(JSP)
INPUT { BORDER-RIGHT: #c0d3dc 1px solid; BORDER-TOP: #c0d3dc 1px solid; BORDER-LEFT: #c0d3dc 1px solid; BORDER-BOTTOM: #c0d3dc 1px solid; font-family: verdana; HEIGHT: 19px}
BODY {font-family:arial,helvetica,Tahoma; font-size: 9pt; color:′094A82′}
dim hj,hji
sub document_onkeypress()
if window.event.srcelement.id="num" and window.event.keycode="13" then
call retu_cn()
end if
end sub
sub window_onload()
document.fmSubmit.t1.focus()
end sub
SUB retu_cn()
dim n,m_hj,s,ch,ch2,ch3,num
num=Replace(trim(document.fmSubmit.t1.value),",","",1,-1,1)
if num="" then
MsgBox "您还没有输入金额!"
document.fmSubmit.t1.focus()
exit sub
End If
if IsNumeric(num)=False then
MsgBox "您输入的不是金额!"
document.fmSubmit.t1.focus()
exit sub
End If
n=FormatNumber(num,2,-1)
num=n
n=Replace(n,",","",1,-1,1)
If len(n)>15 Then
MsgBox "金额必须小于千亿!"
document.fmSubmit.t1.focus()
exit sub
End If
hj=space(0)
s="840"
ch="壹贰叁肆伍陆柒捌玖"
ch2="仟佰拾 "
ch3="亿万元"
for x=1 to 3
m=cstr(int(n/10^FormatNumber(mid(s,x,1),0,-1)))
m=space(4-len(m))+m
m_hj=space(0)
if m<>" 0" then
for y=1 to 4
if mid(m,y,1)<>space(1) and mid(m,y,1)<>"0" then
m_hj=trim(m_hj+mid(ch,FormatNumber(mid(m,y,1),0,-1),1)+mid(ch2,y,1))
else
if mid(m,y,1)=space(1) or mid(m,y,1)="0" then
m_hj=m_hj
if right(m_hj,1)="零" then
m_hj=m_hj+space(0)
else
m_hj=m_hj+"零"
end if
else
m_hj=m_hj
end if
end if
next
if right(m_hj,1)="零" then
m_hj=mid(m_hj,1,len(m_hj)-1)+mid(ch3,x,1)
if x=3 then
m_hj=m_hj+space(0)
else
m_hj=m_hj+"零"
end if
else
m_hj=m_hj+mid(ch3,x,1)
end if
if right(hj,1)="零" and mid(m_hj,1,1)="零" then
hj=hj+mid(m_hj,2,len(m_hj)-1)
else
hj=hj+m_hj
end if
else
if x=3 then
if right(hj,1)="零" then
if trim(hj)="零" then
hj=hj+space(0)
else
hj=mid(hj,1,len(hj)-1)+"元"
end if
else
if trim(hj)="零" then
hj=hj+space(0)
else
hj=hj+"元"
end if
end if
else
if right(hj,1)="零" then
hj=hj+space(0)
else
hj=hj+"零"
end if
end if
end if
if n-int(n)=0 then
n=n-int(FormatNumber(m,0,-1))*10^int(FormatNumber(mid(s,x,1),0,-1))
else
tt=FormatNumber("0."+mid(cstr(n),Instr(1,n,".")+1,2),2)
n=int(n)
n=n-int(FormatNumber(m,0,-1))*10^int(FormatNumber(mid(s,x,1),0,-1))
n=n+tt
end if
next
m=mid(cstr(n),2,2)
if trim(len(m))<>2 then
m=m+"0"
end if
if n*100=0 then
if left(hj,1)="零" then
if right(hj,1)="零" then
hj=hj+"元整"
else
hj=mid(hj,2,len(hj)-1)+"整"
end if
else
if right(hj,1)="零" then
hj=mid(hj,1,len(hj)-1)+"整"
else
hj=hj+"整"
end if
end if
else
if right(hj,1)="零" then
hj=mid(hj,1,len(hj)-1)
else
hj=hj
end if
if mid(m,1,1)="0" or mid(m,1,1)=space(1) then
hj=hj+"零"
else
hj=hj+mid(ch,FormatNumber(mid(m,1,1),0,-1),1)+"角"
end if
if mid(hj,1,1)="零" then
hj=mid(hj,2,len(hj)-1)
else
hj=hj
end if
if mid(m,2,1)="0" then
hj=hj+"整"
else
hj=hj+mid(ch,FormatNumber(mid(m,2,1),0,-1),1)+"分"
end if
end if
if num=".00" then
document.fmSubmit.t1.value="/0.00"
else
document.fmSubmit.t1.value=num
end if
document.fmSubmit.t2.value=""
hji=1
call read()
End Sub
SUB read()
MyVar=mid(hj,hji,1)
document.fmSubmit.t2.value="/document.fmSubmit.t2.value+MyVar"
Select Case MyVar
Case "零" document.all("bgsoundone").src=""
Case "壹" document.all("bgsoundone").src=""
Case "贰" document.all("bgsoundone").src=""
Case "叁" document.all("bgsoundone").src=""
Case "肆" document.all("bgsoundone").src=""
Case "伍" document.all("bgsoundone").src=""
Case "陆" document.all("bgsoundone").src=""
Case "柒" document.all("bgsoundone").src=""
Case "捌" document.all("bgsoundone").src=""
Case "玖" document.all("bgsoundone").src=""
Case "拾" document.all("bgsoundone").src=""
Case "佰" document.all("bgsoundone").src=""
Case "仟" document.all("bgsoundone").src