| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5935 人关注过本帖, 2 人收藏
标题:金额大小写转换问题
取消只看楼主 加入收藏
zyangc
Rank: 1
等 级:新手上路
帖 子:12
专家分:5
注 册:2016-4-30
结帖率:100%
收藏(2)
已结贴  问题点数:10 回复次数:1 
金额大小写转换问题
text2的值为100 这个转换了显示 壹佰零拾零元 零角零分 怎么才能显示为壹佰元
模块代码如下
程序代码:
Function RMBChinese(ByVal Rmb As Double) As String
    On Error Resume Next
    Dim Rmbexp As String, Rmbda As String, Expda As String, Lent As Integer, Ntyp As Integer, Icnt As Integer, i As Integer, Trmb As String

    Rmb = Format(Rmb, "###0.00")
    If Rmb > 999999999999.99 Then
        RMBChinese = "需转换的金额整数长度超过了12位!"
        Exit Function
    End If

    Rmbexp = "分角元拾佰仟万拾佰仟亿拾佰仟"
    Rmbda = "零壹贰叁肆伍陆柒捌玖"
    Ntyp = 0
    Trmb = Replace(CStr(Format(Rmb, "0.00")), ".", "")

    If Left(Trmb, 1) = "-" Then
        Trmb = Mid(Trmb, 2)
        Ntyp = 1
    End If

    Expda = ""
    Icnt = Len(Trmb)

    For i = 1 To Icnt
        Expda = Mid(Rmbda, Val(Mid(Trmb, Icnt - i + 1, 1)) + 1, 1) + IIf(Mid(Rmbexp, i, 1) = "", Mid(Rmbexp, i, 1) + " ", Mid(Rmbexp, i, 1)) + Expda
    Next
    RMBChinese = IIf(Ntyp = 1, "" + Expda, Expda)
End Function
2016-11-06 00:16
zyangc
Rank: 1
等 级:新手上路
帖 子:12
专家分:5
注 册:2016-4-30
收藏
得分:0 
回复 2楼 chen3523
谢谢,已经解决了
程序代码:
Public Function Converts(NumStr As String) As String

    Select Case Val(NumStr)
      Case 0
        Converts = ""
      Case 1
        Converts = ""
      Case 2
        Converts = ""
      Case 3
        Converts = ""
      Case 4
        Converts = ""
      Case 5
        Converts = ""
      Case 6
         Converts = ""
      Case 7
         Converts = ""
      Case 8
         Converts = ""
      Case 9
         Converts = ""
    End Select
End Function


'转换为金额函数
Public Function Up(Dxs As String) As String
'检测为空时
If Trim(Dxs) = "" Then
   Exit Function
End If
If Left(Dxs, 1) = "-" Then
   Dim Fs As Boolean
   Fs = True
   Dxs = Right(Dxs, Len(Dxs) - 1)
End If
  
  Dim Sw As Integer, SzP As Integer, SzUp As Integer, TempStr As String, DXStr As String
    Sw = Len(Trim(Dxs))
    SzP = InStr(1, Trim(Dxs), ".")
    Dim i As Long
If SzP = 0 Then
     For i = 1 To Sw
         TempStr = Right(Trim(Dxs), i)
         TempStr = Left(TempStr, 1)
         TempStr = Converts(TempStr)
         Select Case i
           Case 1
               If TempStr = "" Then
                  TempStr = ""
                   Else
                  TempStr = TempStr + ""
               End If
           Case 2
               If TempStr = "" Then
                  TempStr = ""
                Else
                  TempStr = TempStr + ""
               End If
           Case 3
               If TempStr = "" Then
                  TempStr = ""
                   Else
                  TempStr = TempStr + ""
               End If
            Case 4
               If TempStr = "" Then
                  TempStr = ""
                   Else
                  TempStr = TempStr + ""
               End If
            Case 5
               If TempStr = "" Then
                  TempStr = ""
                   Else
                  TempStr = TempStr + ""
               End If
            Case 6
               If TempStr = "" Then
                  TempStr = ""
                   Else
                  TempStr = TempStr + ""
               End If
            Case 7
               If TempStr = "" Then
                  TempStr = ""
                   Else
                  TempStr = TempStr + ""
               End If
            Case 8
               If TempStr = "" Then
                  TempStr = ""
                   Else
                  TempStr = TempStr + ""
               End If
            Case 9
               If TempStr = "" Then
                  TempStr = "亿"
                   Else
                  TempStr = TempStr + "亿"
               End If
         End Select
    Dim TempA As String
        TempA = Left(Trim(DXStr), 1)
    If TempStr = "" Then
      Select Case TempA
       Case ""
            DXStr = DXStr
       Case ""
            DXStr = DXStr
       Case ""
            DXStr = DXStr
       Case "亿"
            DXStr = DXStr
       Case Else
            DXStr = TempStr + DXStr
      End Select
      Else
       DXStr = TempStr + DXStr
    End If
     Next
  Else
    For i = 1 To SzP - 1
         TempStr = Right(Trim(Dxs), i + (Sw - SzP + 1))
         TempStr = Left(TempStr, 1)
         TempStr = Converts(TempStr)
         Select Case i
           Case 1
               If TempStr = "" Then
                  TempStr = ""
                   Else
                  TempStr = TempStr + ""
               End If
           Case 2
               If TempStr = "" Then
                  TempStr = ""
                Else
                  TempStr = TempStr + ""
               End If
           Case 3
               If TempStr = "" Then
                  TempStr = ""
                   Else
                  TempStr = TempStr + ""
               End If
            Case 4
               If TempStr = "" Then
                  TempStr = ""
                   Else
                  TempStr = TempStr + ""
               End If
            Case 5
               If TempStr = "" Then
                  TempStr = ""
                   Else
                  TempStr = TempStr + ""
               End If
            Case 6
               If TempStr = "" Then
                  TempStr = ""
                   Else
                  TempStr = TempStr + ""
               End If
            Case 7
               If TempStr = "" Then
                  TempStr = ""
                   Else
                  TempStr = TempStr + ""
               End If
            Case 8
               If TempStr = "" Then
                  TempStr = ""
                   Else
                  TempStr = TempStr + ""
               End If
            Case 9
               If TempStr = "" Then
                  TempStr = "亿"
                   Else
                  TempStr = TempStr + "亿"
               End If
            Case Else
              '超过999999999时自动删除
              TempStr = ""
         End Select
        TempA = Left(Trim(DXStr), 1)
    If TempStr = "" Then
      Select Case TempA
       Case ""
            DXStr = DXStr
       Case ""
            DXStr = DXStr
       Case ""
            DXStr = DXStr
       Case "亿"
            DXStr = DXStr
       Case Else
            DXStr = TempStr + DXStr
      End Select
      Else
       DXStr = TempStr + DXStr
    End If
     Next
'计算小数
   Dim DxstrX As String, XStr As String
      XStr = Right(Trim(Dxs), Sw - SzP)
        For i = 1 To Sw - SzP
         TempStr = Left(XStr, i)
         TempStr = Right(TempStr, 1)
         TempStr = Converts(TempStr)
         Select Case i
           Case 1
            If TempStr = "" Then
               TempStr = ""
               Else
               TempStr = TempStr + ""
            End If
           Case 2
            If TempStr = "" Then
               TempStr = ""
               Else
               TempStr = TempStr + ""
               End If
            Case Else
              '超过两位小数时,自动删除
              TempStr = ""
         End Select
        DxstrX = DxstrX + TempStr
     Next
     DXStr = DXStr + DxstrX
End If
    Up = DXStr
   Sw = InStr(1, Up, "亿万", vbTextCompare)
If Sw > 1 Then
   TempStr = Left(Up, Sw)
   TempStr = TempStr + Right(Up, Len(Up) - Sw - 1)
   Up = TempStr
End If
   Sw = InStr(1, Up, "壹拾", vbTextCompare)
If Sw = 1 Then
   TempStr = Left(Up, Sw - 1)
   TempStr = TempStr + Right(Up, Len(Up) - Sw)
   Up = TempStr
End If
If Up = "" Then
   Up = "零元"
End If
If Fs Then
   Up = "" + Up
End If
End Function

2016-11-06 13:15
快速回复:金额大小写转换问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036326 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved