请提供一段 人民币大小写转换的代码,vb语言吧
时间: 2023-05-31 21:02:45 浏览: 60
以下是VB语言的人民币大小写转换代码:
Private Function ConvertToChineseNumber(ByVal d As Double) As String
Dim strValue As String = ""
Dim strUnit As String() = {"", "拾", "佰", "仟", "万", "拾万", "佰万", "仟万", "亿", "拾亿", "佰亿", "仟亿"}
Dim strNum As String() = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"}
Dim strFraction As String() = {"角", "分"}
Dim i As Integer
Dim strTemp As String
Dim strInt As String = Int(d).ToString
Dim strFractional As String = Right(Round((d - Int(d)) * 100, 2).ToString, 2)
If Len(strInt) > 12 Then
ConvertToChineseNumber = "超出范围"
Exit Function
End If
For i = 1 To Len(strInt)
strTemp = Mid(strInt, i, 1)
If strTemp <> "0" Then
strValue &= strNum(CInt(strTemp)) & strUnit(Len(strInt) - i + 1)
Else
If i = Len(strInt) Then
strValue &= strNum(CInt(strTemp))
Else
If Mid(strInt, i + 1, 1) <> "0" Then
strValue &= strNum(CInt(strTemp))
End If
End If
End If
Next
If strFractional <> "00" Then
For i = 1 To 2
strTemp = Mid(strFractional, i, 1)
If strTemp <> "0" Then
strValue &= strNum(CInt(strTemp)) & strFraction(i - 1)
End If
Next
End If
ConvertToChineseNumber = strValue & "元整"
End Function
调用该函数:
Dim Num As Double
Num = 1234567890.12
MsgBox ConvertToChineseNumber(Num)
'结果为:壹拾贰亿叁仟肆佰伍拾陆万柒仟捌百玖拾元壹角贰分
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)