第一個辦法,這個程序可以進(jìn)行萬億以下的貨幣金額轉(zhuǎn)換(夠用的了吧),其中漢字與數(shù)字均按一位計:
Function AtoC(a As Currency) As String
' 定義兩個字符串,A的值最多是兩位小數(shù).
Dim String1 As String
' 如下定義.
Dim String2 As String
' 如下定義.
Dim String3 As String
' 從原A值中取出的值.
Dim I As Integer
' 循環(huán)變量.
Dim J As Integer
' A的值乘以100的字符串長度.
Dim Ch1 As String
' 數(shù)字的漢語讀法.
Dim Ch2 As String
' 數(shù)字位的漢字讀法.
Dim nZero As Integer
' 用來計算連續(xù)的非零數(shù)是幾個.
String1 = "零壹貳叁肆伍陸柒捌玖"
String2 = "萬仟佰拾億仟佰拾萬仟佰拾元角分"
'MsgBox CStr(a * 100)
If InStr(1, CStr(a * 100), ".") > 0 Then
err.Raise 5000, , "該函數(shù)( AtoC() )只轉(zhuǎn)換兩位小數(shù)以內(nèi)的數(shù)值!"
End If
J = Len(CStr(a * 100))
String2 = Right(String2, J)
' 取出對應(yīng)位數(shù)的StrING2的值.
For I = 1 To J
String3 = Mid(a * 100, I, 1)
' 取出需轉(zhuǎn)換的某一位的值.
If String3 > "0" Then
Ch1 = Mid(String1, Val(String3) + 1, 1)
Ch2 = Mid(String2, I, 1)
nZero = nZero + 1
' 表示本位不為零.
Else
If nZero > 0 Or I = J - 9 Or I = J - 5 Or I = J - 1 Then
If Right(AtoC, 1) = "零" Then AtoC = Left(AtoC, Len(AtoC) - 1)
Ch1 = "零"
Else
Ch1 = ""
End If
If I = J - 10 Then
' 如果轉(zhuǎn)換的數(shù)值需要擴(kuò)大,則要改動以下表達(dá)式 I 的值.
Ch2 = "億"
ElseIf I = J - 6 Then
If nZero > 0 Then
Ch2 = "萬"
' nZero = 0
End If
ElseIf I = J - 2 Then
Ch2 = "元"
ElseIf I = J Then
Ch2 = "整"
Else
Ch2 = ""
End If
nZero = 0
End If
AtoC = AtoC Ch1 Ch2
Next I
AtoC = Replace(AtoC, "零元", "元")
AtoC = Replace(AtoC, "零萬", "萬")
AtoC = Replace(AtoC, "零億", "億")
AtoC = Replace(AtoC, "零整", "整")
' 以上將多余的零去掉
End Function
第二個辦法:照下面寫就成了!
%
dim str(9)
str(0)="零"
str(1)="壹"
str(2)="貳"
str(3)="叁"
str(4)="肆"
str(5)="伍"
str(6)="陸"
str(7)="柒"
str(8)="捌"
str(9)="玖"
aa=Request.form("source")
hh=formatnumber(aa,2,-1)
aa=replace(hh,".","")
aa=replace(aa,",","")
for i=1 to len(aa)
s=mid(aa,i,1)
mynum=str(s)
select case(len(aa)+1-i)
case 1: k= mynum"分"
case 2: k= mynum"角"
case 3: k= mynum"元"
case 4: k= mynum"拾"
case 5: k= mynum"佰"
case 6: k= mynum"仟"
case 7: k= mynum"萬"
case 8: k= mynum"拾"
case 9: k= mynum"佰"
case 10: k= mynum"仟"
end select
m=mk
next
%>
html>
head>
title>精彩春風(fēng)之?dāng)?shù)字大小寫轉(zhuǎn)換/title>
meta http-equiv="Content-Type" content="text/html; charset=gb2312">
/head>
!--
Elseif(s=".") then
n=m
i=i+2
for j=i to len(aa)
s=mid(aa,i,1)
mynum=str(s)
select case(len(aa)+1-i)
case 1: p= mynum"分"
case 2: p= mynum"角"
end select
m=mp
next
-->
body>
form method="post" name="forma">
input type="text" name="source" value="%=hh%>">
=
input type="text" name="result" value="%=m%>" size="40">
input type="submit" name="Submit" value="開始轉(zhuǎn)換" >
/form>
/body>/html>
您可能感興趣的文章:- jsp頁面調(diào)用applet實現(xiàn)人民幣的大小寫轉(zhuǎn)換
- 人民幣數(shù)字轉(zhuǎn)換成大寫形式
- PHP人民幣金額數(shù)字轉(zhuǎn)中文大寫的函數(shù)代碼
- JS實現(xiàn)將人民幣金額轉(zhuǎn)換為大寫的示例代碼
- js實現(xiàn)完美兼容各大瀏覽器的人民幣大小寫相互轉(zhuǎn)換