2012年7月12日 星期四

數字金額轉換國字

請將數字金額輸換成國字,金額從0到100000000的整數(壹億)。
輸入:in.txt
12340
1001
輸出:out.txt
新台幣壹萬貳仟參佰肆拾元整
新台幣壹仟零壹元整

2 則留言:

  1. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    x = Split(" ,拾,佰,仟,萬,拾,佰,仟,億,拾,佰,仟,兆", ",")
    Do While Not EOF(1)
    Input #1, n
    ans = ""
    k = 0
    For i = Len(n) To 1 Step -1
    ans = Mid(n, i, 1) & x(k) & ans
    k = k + 1
    Next
    ans = Replace(ans, "1", "壹")
    ans = Replace(ans, "2", "貳")
    ans = Replace(ans, "3", "參")
    ans = Replace(ans, "4", "肆")
    ans = Replace(ans, "5", "伍")
    ans = Replace(ans, "6", "陸")
    ans = Replace(ans, "7", "柒")
    ans = Replace(ans, "8", "捌")
    ans = Replace(ans, "9", "玖")
    ans = Replace(ans, "0", "零")
    ans = Replace(ans, "零拾", "零")
    ans = Replace(ans, "零佰", "零")
    ans = Replace(ans, "零仟", "零")
    ans = Replace(ans, "零萬", "零")
    Do While InStr(ans, "零零") <> 0
    ans = Replace(ans, "零零", "零")
    Loop
    ans = Replace(ans, " ", "")
    If Mid(ans, Len(ans), 1) = "零" Then ans = Mid(ans, Len(ans) - 1)
    Print #2, "新台幣" & ans & "元整"
    Loop
    Close
    Close
    End
    End Sub

    回覆刪除
  2. Function f(ByVal num1)
    a = Array("零", "壹", "貳", "參", "肆", "伍", "陸", "柒", "捌", "玖")
    '105767
    For I = 1 To Len(num1)
    Mid(num1, I, 1) = a(Mid(num1, I, 1))
    Next I
    b = Array("", "拾", "佰", "仟")
    num2 = ""
    For j = Len(num1) To 1 Step -1
    num2 = Mid(num1, j, 1) & b(((Len(num1) - j) Mod 4)) & num2
    Next j
    c = Array("萬", "億")
    P = 0
    For k = 0 To UBound(c)
    If k = 0 Then P = 7
    If k = 1 Then P = 15
    If Len(num2) > P Then
    num2 = Left(num2, Len(num2) - P) & c(k) & Right(num2, P)
    End If
    Next k
    '105657
    '壹拾零伍仟柒佰陸拾柒
    '壹貳仟參佰肆拾伍陸仟柒佰捌拾玖
    ' k = 0 ,1
    ' p = 7 , 15
    num2 = Replace(num2, "零拾", "零")
    num2 = Replace(num2, "零佰", "零")
    num2 = Replace(num2, "零仟", "零")
    num2 = Replace(num2, "零零零", "零")
    num2 = Replace(num2, "零零", "零")
    num2 = Replace(num2, "零萬", "萬")
    num2 = Replace(num2, "零億", "億")
    If Len(num2) > 2 And Right(num2, 1) = "零" Then
    num2 = Left(num2, Len(num2) - 1)
    End If
    f = num2
    End Function
    Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, n
    Print #2, "新台幣" & f(n) & "元整"
    Close #2
    Close #1
    End
    End Sub

    回覆刪除