'功能模块:数字转英文(货币)大写
'Public Function NumberToString(Number As Double) As String
'调用形式:debug.print NumberToString(1234.32)
'说明:最大支持12位数字,小数点后精确两位
'程序:杨鑫光(Volitation)
Dim StrNO(19) As String
Dim Unit(8) As String
Dim StrTens(9) As String
Public Function NumberToString(Number As Double) As String
Dim Str As String, BeforePoint As String, AfterPoint As String, tmpStr As String
Dim Point As Integer
Dim nBit As Integer
Dim CurString As String
Call Init
'//开始处理
Str = CStr(Round(Number, 2))
' Str = Number
If InStr(1, Str, ".") = 0 Then
BeforePoint = Str
AfterPoint = ""
Else
BeforePoint = Left(Str, InStr(1, Str, ".") - 1)
AfterPoint = Right(Str, Len(Str) - InStr(1, Str, "."))
End If
If Len(BeforePoint) > 12 Then
NumberToString = "Too Big."
Exit Function
End If
Str = ""
Do While Len(BeforePoint) > 0
nNumLen = Len(BeforePoint)
If nNumLen Mod 3 = 0 Then
CurString = Left(BeforePoint, 3)
BeforePoint = Right(BeforePoint, nNumLen - 3)
Else
CurString = Left(BeforePoint, (nNumLen Mod 3))
BeforePoint = Right(BeforePoint, nNumLen - (nNumLen Mod 3))
End If
nBit = Len(BeforePoint) / 3
tmpStr = DecodeHundred(CurString)
If (BeforePoint = String(Len(BeforePoint), "0") Or nBit = 0) And Len(CurString) = 3 Then
If CInt(Left(CurString, 1)) <> 0 And CInt(Right(CurString, 2)) <> 0 Then
tmpStr = Left(tmpStr, InStr(1, tmpStr, Unit(4)) + Len(Unit(4))) & Unit(8) & " " & Right(tmpStr, Len(tmpStr) - (InStr(1, tmpStr, Unit(4)) + Len(Unit(4))))
Else 'If CInt(Left(CurString, 1)) <> 0 And CInt(Right(CurString, 2)) = 0 Then
tmpStr = Unit(8) & " " & tmpStr
End If
End If
If nBit = 0 Then
Str = Trim(Str & " " & tmpStr)
Else
Str = Trim(Str & " " & tmpStr & " " & Unit(nBit))
End If
If Left(Str, 3) = Unit(8) Then Str = Trim(Right(Str, Len(Str) - 3))
If BeforePoint = String(Len(BeforePoint), "0") Then Exit Do
'Debug.Print Str
Loop
BeforePoint = Str
If Len(AfterPoint) > 0 Then
AfterPoint = Unit(6) & " " & DecodeHundred(AfterPoint) & " " & Unit(7)
Else
AfterPoint = Unit(5)
End If
NumberToString = BeforePoint & " " & AfterPoint
End Function
Private Function DecodeHundred(HundredString As String) As String
Dim tmp As Integer
If Len(HundredString) > 0 And Len(HundredString) <= 3 Then
Select Case Len(HundredString)
Case 1
tmp = CInt(HundredString)
If tmp <> 0 Then DecodeHundred = StrNO(tmp)
Case 2
tmp = CInt(HundredString)
If tmp <> 0 Then
If (tmp < 20) Then
DecodeHundred = StrNO(tmp)
Else
If CInt(Right(HundredString, 1)) = 0 Then
DecodeHundred = StrTens(Int(tmp / 10))
Else
DecodeHundred = StrTens(Int(tmp / 10)) & "-" & StrNO(CInt(Right(HundredString, 1)))
End If
End If
End If
Case 3
If CInt(Left(HundredString, 1)) <> 0 Then
DecodeHundred = StrNO(CInt(Left(HundredString, 1))) & "