SSRS 实现数字金额转换为中文大写汉字

比如:

 金额=49,701,120.00,将其转换为“肆仟玖佰柒拾万壹仟壹佰贰拾元整”;金额 289,546.52 ,转换为 “贰拾捌万玖仟伍佰肆拾陆元伍角贰分”。

解决方法:添加VB的转换函数写在CODE里,然后在表达式里调用自定义函数转换。

  如:增加两个占位符表达式,如小数位为0时表达式2添加“整”,

      表达式1=Code.GetCnString(Fields!Amount.Value)

      表达式2=IIF(Fields!Amount.Value)=Fix(Fields!Amount.Value),"整","")

  VB转换函数(转):

'******************货币金额大写转换库 Money2String.dll *********************
'
'
'中文大写转换方法       String GetCnString(String MoneyString)
'最大转化金额           999999999999999999999999.99  (24位整数位,2位小数位)
'方法返回值             转换成功则返回非零长字串,否则返回零长字串
'
'英文大写转换方法       String GetEnString(String MoneyString)
'最大转化金额           999999999999999.99   (15位整数位,2位小数位)
'方法返回值             转换成功则返回非零长字串,否则返回零长字串
'
'
'程序设计 xlFancy       Copyright (C) 2003.03.18 - 2006.12.05
'邮箱地址 xlfancy@21cn.com
'
'**************************************************************************
Option Explicit
'中文大写转换
Public Function GetCnString(ByVal MoneyString As String) As String
Dim i As Long
Dim k As Long
Dim j As Long
Dim n As Long
Dim rmbCapital As String
Dim intString As String
Dim decString As String
Dim tmpString() As String
Dim cnNumber() As String
Dim cnUnit() As String
On Error GoTo cnstr_err:
'初始化中文数字、单位
cnNumber = Split("零,壹,贰,叁,肆,伍,陆,柒,捌,玖", ",")
cnUnit = Split("分,角,元,拾,佰,仟,万,拾,佰,仟,亿,拾,佰,仟,兆,拾,佰,仟,京,拾,佰,仟,垓,拾,佰,仟", ",")
decString = ""
intString = MoneyString
tmpString = Split(MoneyString, ".")
If UBound(tmpString) Then
   intString = tmpString(0)
   decString = tmpString(1)
End If
intString = intString & Left(decString & "00", 2)
rmbCapital = ""
k = Len(intString) - 1
If k > 25 Then  'Len(cnUnit) - 1
   rmbCapital = MoneyString  '超出转换范围,返回原值
Else
   If Val(intString) = 0 Then
      rmbCapital = "零元"
   Else
      For i = 0 To k
          j = Val(Mid(intString, i + 1, 1))
          rmbCapital = rmbCapital & cnNumber(j) & cnUnit(k - i)
      Next i
 
      rmbCapital = Replace(rmbCapital, "零分", "")
      rmbCapital = Replace(rmbCapital, "零角", "")
      rmbCapital = Replace(rmbCapital, "零拾", "")
      rmbCapital = Replace(rmbCapital, "零佰", "")
      rmbCapital = Replace(rmbCapital, "零仟", "")
 
      rmbCapital = Replace(rmbCapital, "零零零", "")
      rmbCapital = Replace(rmbCapital, "零零", "")
 
      rmbCapital = Replace(rmbCapital, "零元", "")
      rmbCapital = Replace(rmbCapital, "零万", "")
      rmbCapital = Replace(rmbCapital, "零亿", "亿")
      rmbCapital = Replace(rmbCapital, "零兆", "")
      rmbCapital = Replace(rmbCapital, "零京", "")
      rmbCapital = Replace(rmbCapital, "零垓", "")
 
      rmbCapital = Replace(rmbCapital, "垓京兆亿万", "")
      rmbCapital = Replace(rmbCapital, "垓京兆亿", "")
      rmbCapital = Replace(rmbCapital, "京兆亿万", "")
      rmbCapital = Replace(rmbCapital, "垓京兆", "")
      rmbCapital = Replace(rmbCapital, "京兆亿", "")
      rmbCapital = Replace(rmbCapital, "兆亿万", "")
      rmbCapital = Replace(rmbCapital, "垓京", "")
      rmbCapital = Replace(rmbCapital, "垓兆", "")
      rmbCapital = Replace(rmbCapital, "垓亿", "")
      rmbCapital = Replace(rmbCapital, "垓万", "")
      rmbCapital = Replace(rmbCapital, "京兆", "")
      rmbCapital = Replace(rmbCapital, "京亿", "")
      rmbCapital = Replace(rmbCapital, "京万", "")
      rmbCapital = Replace(rmbCapital, "兆亿", "")
      rmbCapital = Replace(rmbCapital, "兆万", "")
      rmbCapital = Replace(rmbCapital, "亿万", "亿")
 
      '无小数位时
      If Mid(rmbCapital, Len(rmbCapital), 1) = "" Then
         rmbCapital = Left(rmbCapital, Len(rmbCapital) - 1)
      End If
      '无整数位时
      If Left(rmbCapital, 1) = "" Then
         rmbCapital = Mid(rmbCapital, 2, Len(rmbCapital) - 1)
      End If
      '无角币位时
      If Left(rmbCapital, 1) = "" Then
         rmbCapital = Mid(rmbCapital, 2, Len(rmbCapital) - 1)
      End If
   End If
End If
cnstr_exit:
GetCnString = rmbCapital
Exit Function
cnstr_err:
rmbCapital = ""  '非数字类型错误,返回零长字串
Resume cnstr_exit
End Function
'英文大写转换
Public Function GetEnString(ByVal MoneyString As String) As String
Dim n As Long
Dim k As Long
Dim i1 As Long
Dim i2 As Long
Dim i3 As Long
Dim curPoint As Long
Dim strbuff1 As String
Dim strBuff2 As String
Dim strBuff3 As String
Dim engCapital As String    '保存英文大写字串
Dim intString As String     '保存整数部分字串
Dim decString As String     '保存小数部分字串
Dim tmpString() As String
Dim enSmallNumber() As String
Dim enLargeNumber() As String
Dim enUnit() As String
On Error GoTo enstr_err
'初始化英文数字、单位
enSmallNumber = Split(",ONE,TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT,NINE,TEN,ELEVEN,TWELVE,THIRTEEN,FOURTEEN,FIFTEEN,SIXTEEN,SEVENTEEN,EIGHTEEN,NINETEEN", ",")
enLargeNumber = Split("TWENTY,THIRTY,FORTY,FIFTY,SIXTY,SEVENTY,EIGHTY,NINETY", ",")
enUnit = Split(",THOUSAND,MILLION,BILLION,TRILLION", ",")
decString = ""
intString = MoneyString
tmpString = Split(MoneyString, ".")
If UBound(tmpString) Then
   intString = tmpString(0)
   decString = tmpString(1)
End If
decString = Left(decString & "00", 2)
engCapital = ""
curPoint = Len(intString)
If curPoint > 0 And curPoint < 16 Then
     '以下处理整数部分
     k = 0
     Do While (curPoint > 0)
         strbuff1 = ""
         strBuff2 = ""
         strBuff3 = ""
         If curPoint >= 3 Then
             n = Val(Mid(intString, curPoint - 2, 3))
             If n <> 0 Then
                 i1 = Int(n / 100)              '取佰位数值
                 i2 = Int((n - i1 * 100) / 10'取拾位数值
                 i3 = n Mod 10                  '取个位数值
                 If i1 <> 0 Then
                     strbuff1 = enSmallNumber(i1) + " HUNDRED "
                 End If
 
                 If i2 <> 0 Then
                     If i2 = 1 Then
                         strBuff2 = enSmallNumber(i2 * 10 + i3) & " "
                     Else
                         strBuff2 = enLargeNumber(i2 - 2) & " "
                         If i3 <> 0 Then
                             strBuff3 = enSmallNumber(i3) & " "
                         End If
                     End If
                 Else
                     If i3 <> 0 Then
                         strBuff3 = enSmallNumber(i3) & " "
                     End If
                 End If
                 engCapital = strbuff1 & strBuff2 & strBuff3 & enUnit(k) & " " & engCapital
             End If
         Else
             n = Val(Left(intString, curPoint))
             If n <> 0 Then
                 i2 = Int(n / 10)   '取拾位数值
                 i3 = n Mod 10      '取个位数值
                 If i2 <> 0 Then
                     If i2 = 1 Then
                         strBuff2 = enSmallNumber(i2 * 10 + i3) & " "
                     Else
                         strBuff2 = enLargeNumber(i2 - 2) & " "
                         If i3 <> 0 Then
                             strBuff3 = enSmallNumber(i3) & " "
                         End If
                     End If
                 Else
                     If i3 <> 0 Then
                         strBuff3 = enSmallNumber(i3) & " "
                     End If
                 End If
                 engCapital = strBuff2 & strBuff3 & enUnit(k) & " " & engCapital
             End If
         End If
         k = k + 1
         curPoint = curPoint - 3
     Loop
     engCapital = Trim(engCapital)
     '以下处理小数部分
     strBuff2 = ""
     strBuff3 = ""
     n = Val(decString)
     If n <> 0 Then
          i2 = Int(n / 10)   '取拾位数值
          i3 = n Mod 10      '取个位数值
          If i2 <> 0 Then
              If i2 = 1 Then
                  strBuff2 = enSmallNumber(i2 * 10 + i3) & " "
              Else
                  strBuff2 = enLargeNumber(i2 - 2) & " "
                  If i3 <> 0 Then
                      strBuff3 = enSmallNumber(i3) & " "
                  End If
              End If
          Else
              If i3 <> 0 Then
                  strBuff3 = enSmallNumber(i3) & " "
              End If
          End If
 
         '将小数字串追加到整数字串后
          If Len(engCapital) > 0 Then
              engCapital = engCapital & " AND CENTS " & strBuff2 & strBuff3  '有整数部分时
          Else
              engCapital = "CENTS " & strBuff2 & strBuff3  '只有小数部分时
          End If
     End If
     engCapital = Trim(engCapital)
Else
     engCapital = MoneyString  '超出转换范围,返回原值
End If
enstr_exit:
GetEnString = engCapital
Exit Function
enstr_err:
engCapital = ""  '转换错误,返回零长字串
Resume enstr_exit
End Function

 

转载于:https://www.cnblogs.com/stayting/p/6912024.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值