|
Function SAY(数量 As Long) As String
Dim buff As String, done As String
Static units(10) As String, teens(10) As String
Static tens(10) As String, denoms(4) As String
Dim length As Integer, i As Integer, passes As Integer, temp As Integer
units(1) = "ONE ": units(2) = "TWO ": units(3) = "THREE "
units(4) = "FOUR ": units(5) = "FIVE ": units(6) = "SIX "
units(7) = "SEVEN ": units(8) = "EIGHT ": units(9) = "NINE "
teens(0) = "TEN ": teens(1) = "ELEVEN ": teens(2) = "TWELVE ": teens(3) = "THIRTEEN "
teens(4) = "FOURTEEN ": teens(5) = "FIFTEEN ": teens(6) = "SIXTEEN "
teens(7) = "SEVENTEEN ": teens(8) = "EIGHTEEN ": teens(9) = "NINETEEN "
tens(1) = "TEN": tens(2) = "TWENTY": tens(3) = "THIRTY"
tens(4) = "FORTY": tens(5) = "FIFTY": tens(6) = "SIXTY"
tens(7) = "SEVENTY": tens(8) = "EIGHTY": tens(9) = "NINETY"
denoms(1) = "HUNDRED ": denoms(2) = "THOUSAND ": denoms(3) = "MILLION "
buff = Format$(数量, "#########")
length = Len(buff)
temp = 0
Do While (length > 0)
Select Case (length Mod 3)
Case 0
If Len(done) > 0 Then
done = done & denoms(length / 3 + 1)
End If
If Mid$(buff, 1, 1) <> "0" Then
i = Val(Mid$(buff, 1, 1))
done = done & units(i)
done = done & denoms(1)
End If
Case 1
If Mid$(buff, 1, 1) <> "0" Then
i = Val(Mid$(buff, 1, 1))
If Len(done) > 0 And Mid$(buff, 1, 1) <> "0" And temp = 0 Then
done = done & "AND "
End If
done = done & units(i)
End If
Case 2
If Mid$(buff, 1, 1) = "1" Then
i = Val(Mid$(buff, 2, 1))
If Len(done) > 0 And Mid$(buff, 1, 1) <> "0" Then
done = done & "AND "
End If
done = done & teens(i)
length = length - 1
buff = Mid$(buff, 2)
Else
i = Val(Mid$(buff, 1, 1))
If Len(done) > 0 And Mid$(buff, 1, 1) <> "0" Then
done = done & "AND "
End If
done = done & tens(i)
If Mid$(buff, 1, 1) <> "0" And Mid$(buff, 2, 1) <> "0" Then
done = done & "-"
temp = 1
Else
If Mid$(buff, 1, 1) > "1" And Mid$(buff, 2, 1) = "0" Then
done = done & " "
End If
temp = 0
End If
End If
End Select
length = length - 1
buff = Mid$(buff, 2)
Loop
If 数量 < 1000000000 Then
SAY = done
Else
SAY = "大于等于拾亿"
End If
End Function |
|