明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

精華區(qū)中的“貨幣大寫轉(zhuǎn)換函數(shù)”用起來不是很方便,更改如下:

[摘要]<%Function ChangeNumToDx(SourceNum) Dim String1 '如下定義 Dim String2 '如下定義 Dim String3 '從原SourceNum值中取出的值 Dim I ...

<%
Function ChangeNumToDx(SourceNum)
    Dim String1    '如下定義
    Dim String2    '如下定義
    Dim String3    '從原SourceNum值中取出的值
    Dim I         '循環(huán)變量
    Dim J         'SourceNum的值乘以100的字符串長度
    Dim Ch1        '數(shù)字的漢語讀法
    Dim Ch2        '數(shù)字位的漢字讀法
    Dim nZero     '用來計(jì)算連續(xù)的零值是幾個(gè)

    String1 = "零壹貳叁肆伍陸柒捌玖"
    String2 = "萬仟佰拾億仟佰拾萬仟佰拾元角分"
    nZero = 0
    ChangeNumToDx=""

    If Not IsNumeric(SourceNum) Then
        SourceNum="0"
    End If

    If InStr(1, CStr(SourceNum * 100), ".") <> 0 Then
        err.Raise 5000, , "此函數(shù)( AtoC() )只能轉(zhuǎn)換小數(shù)點(diǎn)后有兩位以內(nèi)的數(shù)!"
    End If
    
    J = Len(CStr(SourceNum * 100))
    String2 = Right(String2, J)                             '取出對(duì)應(yīng)位數(shù)的STRING2的值
    
    For I = 1 To J
        String3 = Mid(SourceNum * 100, I, 1)                        '取出需轉(zhuǎn)換的某一位的值
        
        If I <> (J - 3) + 1 And I <> (J - 7) + 1 And I <> (J - 11) + 1 And I <>(J - 15) + 1 Then
            If String3 = 0 Then
                Ch1 = ""
                Ch2 = ""
                nZero = nZero + 1
            ElseIf String3 <> 0 And nZero <> 0 Then
                Ch1 = "零" & Mid(String1, clng(String3) + 1, 1)
                Ch2 = Mid(String2, I, 1)
                nZero = 0
            Else
                Ch1 = Mid(String1, clng(String3) + 1, 1)
                Ch2 = Mid(String2, I, 1)
                nZero = 0
            End If
        Else                                                '該位是萬億,億,萬,元位等關(guān)鍵位
            If String3 <> 0 And nZero <> 0 Then
                Ch1 = "零" & Mid(String1, clng(String3) + 1, 1)
                Ch2 = Mid(String2, I, 1)
                nZero = 0
            ElseIf String3 <> 0 And nZero = 0 Then
                Ch1 = Mid(String1, clng(String3) + 1, 1)
                Ch2 = Mid(String2, I, 1)
                nZero = 0
            ElseIf String3 = 0 And nZero >= 3 Then
                Ch1 = ""
                Ch2 = ""
                nZero = nZero + 1
            Else
                Ch1 = ""
                Ch2 = Mid(String2, I, 1)
                nZero = nZero + 1
            End If
            
            If I = (J - 11) + 1 Or I = (J - 3) + 1 Then     '如果該位是億位或元位,則必須寫上
                Ch2 = Mid(String2, I, 1)
            End If
            
        End If
        AtoC = AtoC & Ch1 & Ch2
        
        If I = J And String3 = 0 Then                       '最后一位(分)為0時(shí),加上“整”
            ChangeNumToDx = AtoC & "整"
        End If
        
    Next

    If SourceNum=0 Then
        ChangeNumToDx="零元整"
    End If
    
End Function

'以下為例子
Response.Write ChangeNumToDx(100000)
'結(jié)果為:壹拾萬元整
%>