我想用asp和vbscript或javascript实现,把钱转换成中国的钱,比如123456元变成拾贰万叁千肆百伍拾陆圆整,谢谢各位大侠
---------------------------------------------------------------
一段收藏:::
1<script>
2document.write(Chinese("1.01"));
3document.write("
4"+Chinese("15700.4"));
5document.write("
6"+Chinese("143260.3"));
7document.write("
8"+Chinese("164372.4"));
9document.write("
10"+Chinese("52508.6"));
11
12function Chinese(num){
13var arr1=new Array("仟","佰","拾","亿","仟","佰","拾","万","仟","佰","拾","元","点","角","分")
14var arr3=new Array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖")
15var point=num.indexOf(".")
16if(point<0)point=num.length
17var len=arr1.length-point-3
18var strRet="",lastChar="";
19for(i=0;i<num.length;i++){
20if(i!=point){
21val=arr1[i+len]
22if(num.charAt(i)!="0")
23strRet+=arr3[num.charAt(i)]+val;
24else{
25lastChar=strRet.substr(strRet.length-1)
26if(val=="亿" ¦ ¦val=="万" ¦ ¦val=="元" ¦ ¦val=="分"){
27if(lastChar=="零")strRet=strRet.substr(0,strRet.length-1);
28lastChar=strRet.substr(strRet.length-1)
29if(!((val=="万"&&lastChar=="亿") ¦ ¦(val=="分"&&lastChar=="角")))strRet+=val
30}else{
31if(lastChar!="零")strRet+="零";
32}
33}
34}
35}
36return strRet
37}
38</script>
---------------------------------------------------------------
剽窃高手的,^_^
1<script language="VBScript">
2dim hj,hji
3sub document_onkeypress()
4if window.event.srcelement.id="num" and window.event.keycode="13" then
5call retu_cn()
6end if
7end sub
8sub window_onload()
9document.fmSubmit.t1.focus()
10end sub
11SUB retu_cn()
12dim n,m_hj,s,ch,ch2,ch3,num
13num=Replace(trim(document.fmSubmit.t1.value),",","",1,-1,1)
14if num="" then
15MsgBox "您还没有输入金额!"
16document.fmSubmit.t1.focus()
17exit sub
18End If
19if IsNumeric(num)=False then
20MsgBox "您输入的不是金额!"
21document.fmSubmit.t1.focus()
22exit sub
23End If
24n=FormatNumber(num,2,-1)
25num=n
26n=Replace(n,",","",1,-1,1)
27If len(n)>15 Then
28MsgBox "金额必须小于千亿!"
29document.fmSubmit.t1.focus()
30exit sub
31End If
32hj=space(0)
33s="840"
34ch="壹贰叁肆伍陆柒捌玖"
35ch2="仟佰拾 "
36ch3="亿万元"
37for x=1 to 3
38m=cstr(int(n/10^FormatNumber(mid(s,x,1),0,-1)))
39m=space(4-len(m))+m
40m_hj=space(0)
41if m<>" 0" then
42for y=1 to 4
43if mid(m,y,1)<>space(1) and mid(m,y,1)<>"0" then
44m_hj=trim(m_hj+mid(ch,FormatNumber(mid(m,y,1),0,-1),1)+mid(ch2,y,1))
45else
46if mid(m,y,1)=space(1) or mid(m,y,1)="0" then
47m_hj=m_hj
48if right(m_hj,1)="零" then
49m_hj=m_hj+space(0)
50else
51m_hj=m_hj+"零"
52end if
53else
54m_hj=m_hj
55end if
56end if
57next
58if right(m_hj,1)="零" then
59m_hj=mid(m_hj,1,len(m_hj)-1)+mid(ch3,x,1)
60if x=3 then
61m_hj=m_hj+space(0)
62else
63m_hj=m_hj+"零"
64end if
65else
66m_hj=m_hj+mid(ch3,x,1)
67end if
68if right(hj,1)="零" and mid(m_hj,1,1)="零" then
69hj=hj+mid(m_hj,2,len(m_hj)-1)
70else
71hj=hj+m_hj
72end if
73else
74if x=3 then
75if right(hj,1)="零" then
76if trim(hj)="零" then
77hj=hj+space(0)
78else
79hj=mid(hj,1,len(hj)-1)+"元"
80end if
81else
82if trim(hj)="零" then
83hj=hj+space(0)
84else
85hj=hj+"元"
86end if
87end if
88else
89if right(hj,1)="零" then
90hj=hj+space(0)
91else
92hj=hj+"零"
93end if
94end if
95end if
96if n-int(n)=0 then
97n=n-int(FormatNumber(m,0,-1))*10^int(FormatNumber(mid(s,x,1),0,-1))
98else
99tt=FormatNumber("0."+mid(cstr(n),Instr(1,n,".")+1,2),2)
100n=int(n)
101n=n-int(FormatNumber(m,0,-1))*10^int(FormatNumber(mid(s,x,1),0,-1))
102n=n+tt
103end if
104next
105m=mid(cstr(n),2,2)
106if trim(len(m))<>2 then
107m=m+"0"
108end if
109if n*100=0 then
110if left(hj,1)="零" then
111if right(hj,1)="零" then
112hj=hj+"元整"
113else
114hj=mid(hj,2,len(hj)-1)+"整"
115end if
116else
117if right(hj,1)="零" then
118hj=mid(hj,1,len(hj)-1)+"整"
119else
120hj=hj+"整"
121end if
122end if
123else
124if right(hj,1)="零" then
125hj=mid(hj,1,len(hj)-1)
126else
127hj=hj
128end if
129if mid(m,1,1)="0" or mid(m,1,1)=space(1) then
130hj=hj+"零"
131else
132hj=hj+mid(ch,FormatNumber(mid(m,1,1),0,-1),1)+"角"
133end if
134if mid(hj,1,1)="零" then
135hj=mid(hj,2,len(hj)-1)
136else
137hj=hj
138end if
139if mid(m,2,1)="0" then
140hj=hj+"整"
141else
142hj=hj+mid(ch,FormatNumber(mid(m,2,1),0,-1),1)+"分"
143end if
144end if
145if num=".00" then
146document.fmSubmit.t1.value="0.00"
147else
148document.fmSubmit.t1.value=num
149end if
150document.fmSubmit.t2.value=hj
151hji=1
152End Sub
153SUB read()
154MyVar=mid(hj,hji,1)
155document.fmSubmit.t2.value=document.fmSubmit.t2.value+MyVar
156Select Case MyVar
157Case "零" document.all("bgsoundone").src="http://go.163.com/yjsj/wav/0.wav"
158Case "壹" document.all("bgsoundone").src="http://go.163.com/yjsj/wav/1.wav"
159Case "贰" document.all("bgsoundone").src="http://go.163.com/yjsj/wav/2.wav"
160Case "叁" document.all("bgsoundone").src="http://go.163.com/yjsj/wav/3.wav"
161Case "肆" document.all("bgsoundone").src="http://go.163.com/yjsj/wav/4.wav"
162Case "伍" document.all("bgsoundone").src="http://go.163.com/yjsj/wav/5.wav"
163Case "陆" document.all("bgsoundone").src="http://go.163.com/yjsj/wav/6.wav"
164Case "柒" document.all("bgsoundone").src="http://go.163.com/yjsj/wav/7.wav"
165Case "捌" document.all("bgsoundone").src="http://go.163.com/yjsj/wav/8.wav"
166Case "玖" document.all("bgsoundone").src="http://go.163.com/yjsj/wav/9.wav"
167Case "拾" document.all("bgsoundone").src="http://go.163.com/yjsj/wav/10.wav"
168Case "佰" document.all("bgsoundone").src="http://go.163.com/yjsj/wav/b.wav"
169Case "仟" document.all("bgsoundone").src="http://go.163.com/yjsj/wav/q.wav"
170Case "万" document.all("bgsoundone").src="http://go.163.com/yjsj/wav/w.wav"
171Case "亿" document.all("bgsoundone").src="http://go.163.com/yjsj/wav/y.wav"
172Case "元" document.all("bgsoundone").src="http://go.163.com/yjsj/wav/yuan.wav"
173Case "分" document.all("bgsoundone").src="http://go.163.com/yjsj/wav/fen.wav"
174Case "角" document.all("bgsoundone").src="http://go.163.com/yjsj/wav/jiao.wav"
175Case "整" document.all("bgsoundone").src="http://go.163.com/yjsj/wav/z.wav"
176Case else hji=0
177document.all("bgsoundone").src=""
178exit sub
179End Select
180hji=hji+1
181setTimeout "read",400
182End Sub
183</script>
最完整、最标准的大写金额转换程序,特别是“零”和“整”的转换,最大金额可到仟亿。
并加入了朗读功能,所以说是最完美的大写金额转换程序!
如有BUG请高手指教!!!
1<form id="fmSubmit" method="POST" name="fmSubmit">
2<p>请输入金额:<input id="num" name="T1" size="20" type="text"/> <input name="B1" onclick="retu_cn()" type="button" value="转换大写金额"/></p>
3
4 大写金额:<input name="T2" readonly="" size="55" type="text"/>
5</form>
---------------------------------------------------------------
Create Procedure AtoC
@ChangeMoney Money
as
Set Nocount ON
Declare @String1 char(20)
Declare @String2 char(30)
Declare @String4 Varchar(100)
Declare @String3 Varchar(100) --从原A值中取出的值
Declare @i int