|
你可以用10^n(n=1 to 11)或是0.01、0.1、10.1、10.01试一下你所能搜得到的小写转大写的函数,能正常识别的真是不太多
'==================================lzongb写于2006-06-06晚=======================================
Public Function Num2Letter(num As String) As String
Dim strNum As String, strNum2 As String, strSign As String, strTemp As String, strTemp1 As String
Dim intNumLen As Byte, i As Byte, j As Byte
strTemp = num
If Left(strTemp, 1) = "-" Then
strSign = "负"
strTemp = Right(strTemp, Len(strTemp) - 1)
End If
i = InStr(1, strTemp, ".") '判断是否是小数
If i = 0 Then
strNum = strTemp
strNum2 = ""
Else '小数
strNum = Left(strTemp, i - 1) '提出整数部分
strNum2 = Right(strTemp, Len(strTemp) - i) '提出小数部分
End If
'===================================以下代码处理整数部分=====================================
intNumLen = Len(strNum)
If intNumLen > 12 Then
MsgBox num & "整数部分位数超过12位,本函数无法处理!", vbCritical + vbOKOnly, "提示"
Exit Function
End If
i = intNumLen Mod 4 '除以4的余数
If i <> 0 Then
strNum = String(4 - i, "0") & strNum '将整数部分长度补足为4的整数倍
End If
strNum = StrReverse(strNum) '将整数部分逆序
intNumLen = Len(strNum)
i = Int(intNumLen / 4)
strTemp1 = ""
For j = 1 To i
strTemp = Mid(strNum, 4 * j - 3, 4) '将整数部分每4位分一组
strTemp = CapLetter(strTemp)
If strTemp = "零零零零" Then
strTemp1 = strTemp & strTemp1
Else
strTemp1 = strTemp & Choose(j, "", "万", "亿") & strTemp1
End If
Next j
Do Until InStr(strTemp1, "零零") = 0
strTemp1 = Replace(strTemp1, "零零", "零")
Loop
If Left(strTemp1, 1) = "零" Then strTemp1 = Right(strTemp1, Len(strTemp1) - 1)
If Right(strTemp1, 1) = "零" Then strTemp1 = Left(strTemp1, Len(strTemp1) - 1)
strTemp1 = Replace(strTemp1, "零亿", "亿")
strTemp1 = Replace(strTemp1, "零万", "万")
'=====================================整数部分代码结束=======================================
strTemp = ""
If strNum2 = "" Then '没有小数部分
If strTemp1 = "" Then '整数部分为0
strTemp1 = "零元整"
Else
strTemp1 = strTemp1 & "元整"
End If
Else
If Len(strNum2) = 1 Then strNum2 = strNum2 & "0" '如果小数部分只有1位,补足为2位
If Len(strNum2) > 2 Then
MsgBox num & "小数部分位数超过2位,本函数仅处理前2位,注意并不做四舍五入!", vbOKOnly + vbInformation, "提示"
End If
For i = 1 To 2 '注意:如果小数部分有3位及以上,并不做四舍五入处理,因为Access的Round函数并不精确
strTemp = strTemp & Mid("零壹贰叁肆伍陆柒捌玖", Val(Mid(strNum2, i, 1)) + 1, 1) _
& Choose(i, "角", "分")
Next i
If strTemp1 = "" Then
strTemp1 = "零元" & strTemp
Else
strTemp1 = strTemp1 & "元" & strTemp
End If
End If
Num2Letter = strSign & strTemp1
End Function
Public Function CapLetter(num As String)
Dim i As Byte, j As Byte, strTemp As String
num = StrReverse(num) '再做一次逆序,这样就恢复了原来的顺序
Debug.Print num
For i = 1 To 4
j = Val(Mid(num, i, 1))
strTemp = strTemp & Mid("零壹贰叁肆伍陆柒捌玖", j + 1, 1)
If j <> 0 Then
strTemp = strTemp & Choose(i, "仟", "佰", "拾", "")
End If
Next i
CapLetter = strTemp
End Function
[此贴子已经被作者于2006-6-7 16:48:50编辑过]
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|