'*********************************************************
'* 名称:nNumber2Chinese
'* 功能:数值转换为人民币(汉字)
'* 用法:nNumber2Chinese(数值)
'*********************************************************
Public Function Num2Chi(txtJE As Double) As String
Dim i, K As Integer
Dim NC, nd, ka, chrNum, strZheng As String
Dim c1, c2, c3 As String
Dim K1 As Integer
Dim Zheng As String
Dim Xiao As String
NC = Trim(Format(txtJE, "##0.00"))
c1 = "仟佰拾万仟佰拾亿仟佰拾万仟佰拾元"
c2 = "角分"
c3 = "玖捌柒陆伍肆叁贰壹"
If NC = 0 Then
Num2Chi = "零元整"
Exit Function
End If
Num2Chi = ""
Zheng = Mid(NC, 1, (Len(NC) - 3))
Xiao = Mid(NC, (Len(Zheng) + 2))
If Val(Xiao) <> 0 Then
For i = Len(Xiao) To 1 Step -1
chrNum = Mid(Xiao, i, 1)
If chrNum <> 0 Then
Num2Chi = Mid(c2, i, 1) & Num2Chi
Num2Chi = Mid(c3, (Len(c3) - chrNum + 1), 1) & Num2Chi
End If
Next i
End If
K = 0
If Val(Zheng) <> 0 Then
Num2Chi = "元" & Num2Chi
For i = Len(Zheng) To 1 Step -1
If (Len(Zheng) - i) = 4 Then
Num2Chi = "万" & Num2Chi
ElseIf (Len(Zheng) - i) = 8 Then
Num2Chi = "亿" & Num2Chi
ElseIf (Len(Zheng) - i) = 12 Then
Num2Chi = "万" & Num2Chi
End If
chrNum = Mid(Zheng, i, 1)
If chrNum <> 0 Then
If i = Len(Zheng) Then
Num2Chi = Mid(c3, (Len(c3) - chrNum + 1), 1) & Num2Chi
Else
If (Len(Zheng) - i) <> 4 And (Len(Zheng) - i) <> 8 And (Len(Zheng) - i) <> 12 Then
Num2Chi = Mid(c1, (Len(c1) - K), 1) & Num2Chi
End If
Num2Chi = Mid(c3, (Len(c3) - chrNum + 1), 1) & Num2Chi
End If
Else
If Mid(Num2Chi, 1, 1) <> "元" And Mid(Num2Chi, 1, 1) <> "万" And Mid(Num2Chi, 1, 1) <> "亿" Then
If Mid(Num2Chi, 1, 1) <> "零" Then
Num2Chi = "零" & Num2Chi
End If
End If
End If
K = K + 1
Next i
End If
If Right(Trim(Num2Chi), 1) <> "分" Then
Num2Chi = Num2Chi & "整"
End If
End Function
'* 名称:nNumber2Chinese
'* 功能:数值转换为人民币(汉字)
'* 用法:nNumber2Chinese(数值)
'*********************************************************
Public Function Num2Chi(txtJE As Double) As String
Dim i, K As Integer
Dim NC, nd, ka, chrNum, strZheng As String
Dim c1, c2, c3 As String
Dim K1 As Integer
Dim Zheng As String
Dim Xiao As String
NC = Trim(Format(txtJE, "##0.00"))
c1 = "仟佰拾万仟佰拾亿仟佰拾万仟佰拾元"
c2 = "角分"
c3 = "玖捌柒陆伍肆叁贰壹"
If NC = 0 Then
Num2Chi = "零元整"
Exit Function
End If
Num2Chi = ""
Zheng = Mid(NC, 1, (Len(NC) - 3))
Xiao = Mid(NC, (Len(Zheng) + 2))
If Val(Xiao) <> 0 Then
For i = Len(Xiao) To 1 Step -1
chrNum = Mid(Xiao, i, 1)
If chrNum <> 0 Then
Num2Chi = Mid(c2, i, 1) & Num2Chi
Num2Chi = Mid(c3, (Len(c3) - chrNum + 1), 1) & Num2Chi
End If
Next i
End If
K = 0
If Val(Zheng) <> 0 Then
Num2Chi = "元" & Num2Chi
For i = Len(Zheng) To 1 Step -1
If (Len(Zheng) - i) = 4 Then
Num2Chi = "万" & Num2Chi
ElseIf (Len(Zheng) - i) = 8 Then
Num2Chi = "亿" & Num2Chi
ElseIf (Len(Zheng) - i) = 12 Then
Num2Chi = "万" & Num2Chi
End If
chrNum = Mid(Zheng, i, 1)
If chrNum <> 0 Then
If i = Len(Zheng) Then
Num2Chi = Mid(c3, (Len(c3) - chrNum + 1), 1) & Num2Chi
Else
If (Len(Zheng) - i) <> 4 And (Len(Zheng) - i) <> 8 And (Len(Zheng) - i) <> 12 Then
Num2Chi = Mid(c1, (Len(c1) - K), 1) & Num2Chi
End If
Num2Chi = Mid(c3, (Len(c3) - chrNum + 1), 1) & Num2Chi
End If
Else
If Mid(Num2Chi, 1, 1) <> "元" And Mid(Num2Chi, 1, 1) <> "万" And Mid(Num2Chi, 1, 1) <> "亿" Then
If Mid(Num2Chi, 1, 1) <> "零" Then
Num2Chi = "零" & Num2Chi
End If
End If
End If
K = K + 1
Next i
End If
If Right(Trim(Num2Chi), 1) <> "分" Then
Num2Chi = Num2Chi & "整"
End If
End Function
解决方案 »
- Excel操作如何不触发事件
- 多行编辑框显示行号的问题??
- 如何用VB读取delphi做的代密码的.db文件?
- 如何引用EXCEL9。0的库啊?
- 我定义字段的时候出现了问题
- 我做的VB程序的安装总是出错,请帮忙!
- 上面是要计算1.38MB有多少字节,然后将其值赋给value,请问怎样才正确?
- 如何让MSHFLEXGRID只显示新增的记录
- 急???请问升级vs6.0 SP5解压到哪个目录下?
- 送分了,如何用sendmessage API 向一个应用程序发送“Alt+F”的指令?
- 一个40G的IBM硬盘使用不到3个月(服务器硬盘 一直在转的) up有分
- 如何取得当前打印机的打印模式为横向还是纵向打印?
'* 名称:nNumber2Chinese
'* 功能:数值转换为人民币(汉字)
'* 用法:nNumber2Chinese(数值)
'*********************************************************
Public Function Num2Chi(txtJE As Double) As String
Dim i, K As Integer
Dim NC, nd, ka, chrNum, strZheng As String
Dim c1, c2, c3 As String
Dim K1 As Integer
Dim Zheng As String
Dim Xiao As String
NC = Trim(Format(txtJE, "##0.00"))
c1 = "仟佰拾万仟佰拾亿仟佰拾万仟佰拾元"
c2 = "角分"
c3 = "玖捌柒陆伍肆叁贰壹"
If NC = 0 Then
Num2Chi = "零元整"
Exit Function
End If
Num2Chi = ""
Zheng = Mid(NC, 1, (Len(NC) - 3))
Xiao = Mid(NC, (Len(Zheng) + 2))
If Val(Xiao) <> 0 Then
For i = Len(Xiao) To 1 Step -1
chrNum = Mid(Xiao, i, 1)
If chrNum <> 0 Then
Num2Chi = Mid(c2, i, 1) & Num2Chi
Num2Chi = Mid(c3, (Len(c3) - chrNum + 1), 1) & Num2Chi
End If
Next i
End If
K = 0
If Val(Zheng) <> 0 Then
Num2Chi = "元" & Num2Chi
For i = Len(Zheng) To 1 Step -1
If (Len(Zheng) - i) = 4 Then
Num2Chi = "万" & Num2Chi
ElseIf (Len(Zheng) - i) = 8 Then
Num2Chi = "亿" & Num2Chi
ElseIf (Len(Zheng) - i) = 12 Then
Num2Chi = "万" & Num2Chi
End If
chrNum = Mid(Zheng, i, 1)
If chrNum <> 0 Then
If i = Len(Zheng) Then
Num2Chi = Mid(c3, (Len(c3) - chrNum + 1), 1) & Num2Chi
Else
If (Len(Zheng) - i) <> 4 And (Len(Zheng) - i) <> 8 And (Len(Zheng) - i) <> 12 Then
Num2Chi = Mid(c1, (Len(c1) - K), 1) & Num2Chi
End If
Num2Chi = Mid(c3, (Len(c3) - chrNum + 1), 1) & Num2Chi
End If
Else
If Mid(Num2Chi, 1, 1) <> "元" And Mid(Num2Chi, 1, 1) <> "万" And Mid(Num2Chi, 1, 1) <> "亿" Then
If Mid(Num2Chi, 1, 1) <> "零" Then
Num2Chi = "零" & Num2Chi
End If
End If
End If
K = K + 1
Next i
End If
If Right(Trim(Num2Chi), 1) <> "分" Then
Num2Chi = Num2Chi & "整"
End If
End Function