zoukankan      html  css  js  c++  java
  • RDLC自定义函数 数字转人民币大写(金额) 目前只支持到亿,解决零角问题(转载)

    原文地址:https://www.cnblogs.com/puke/archive/2012/08/02/2619741.html

    代码一:
    'RDLC自定义函数 数字转人民币大写(金额) 目前只支持到亿,解决零角问题
    Function CNMoney(ByVal Money As String, Optional ByVal YB As Boolean = True) As String
            Dim X, Y As String
            Dim I As Integer
            Const Zimu = ".sbqwsbqysbqwsbq" ''定义位置代码
            Const Letter = "0123456789sbqwy.zjf" ''定义汉字缩写
            Const Upcase = "零壹贰叁肆伍陆柒捌玖拾佰仟万亿圆整角分" '定义大写汉字
            Dim Temp As String
            Try
                Temp = Convert.ToString(Format(Convert.ToDouble(Money), "0.00"))
            Catch ex As Exception
                Throw New NotSupportedException("数据给出错误(非数字格式)!")
                CNMoney = "Error."
                Exit Function
            End Try
            If Len(Temp) > 12 Then
                Throw New NotSupportedException("数据太大,无法计算(超亿位无法计算)!")
                CNMoney = "Error."
                Exit Function
            End If
            If InStr(Temp, ".") > 0 Then Temp = Left(Temp, InStr(Temp, ".") - 1)
            X = Format(Convert.ToDouble(Money), "0.00") '格式化货币
            Y = ""
            For I = 1 To Len(X) - 3
                Y = Y & Mid(X, I, 1) & Mid(Zimu, Len(X) - 2 - I, 1)
            Next
            If Right(X, 3) = ".00" Then
                Y = Y & "z" ''***元整
            Else
                If Right(X, 1) = "0" Then
                    Y = Y & Left(Right(X, 2), 1) & "j" & "z" '*元*角*整
                Else
                    Y = Y & Left(Right(X, 2), 1) & "j" & Right(X, 1) & "f" ''*元*角*分
                End If
            End If
            Y = Replace(Y, "0q", "0") ''避免零千(如:40200肆萬零千零贰佰)
            Y = Replace(Y, "0b", "0") ''避免零百(如:41000肆萬壹千零佰)
            Y = Replace(Y, "0s", "0") ''避免零十(如:204贰佰零拾零肆)
            Do While Y <> Replace(Y, "00", "0")
                Y = Replace(Y, "00", "0") ''避免双零(如:1004壹仟零零肆)
            Loop
            Y = Replace(Y, "0y", "y") ''避免零億(如:210億 贰佰壹十零億)
            If Val(Mid(Right(Temp, 4), 1, 1)) > 0 Then
                Y = Replace(Y, "0w", "w0") ''避免无零千(如:102000 拾万贰仟),应该是拾万零贰仟
            Else
                Y = Replace(Y, "0w", "w") ''避免零萬(如:210萬 贰佰壹十零萬)
            End If
            'Y = IIf(Len(X) = 5 And Left(Y, 1) = "1", Right(Y, Len(Y) - 1), Y) ''避免壹十(如:14壹拾肆;10壹拾)
            Y = IIf(Len(X) = 4, Replace(Y, "0.", ""), Replace(Y, "0.", ".")) ''避免零元(如:20.00贰拾零圆;0.12零圆壹角贰分)
            If Len(Temp) >= 9 Then '
                Y = Replace(Y, "yw", "y") '避免亿万元 如 100000000,壹亿万元 应该是壹亿元
            End If '
            For I = 1 To 19
                Y = Replace(Y, Mid(Letter, I, 1), Mid(Upcase, I, 1)) ''大写汉字
            Next
            Y = Y.Replace("零角", "")
            If YB = False Then
                Y = Y.Replace("圆整", "")
            End If
            
            CNMoney = Y
        End Function

    代码放在报表代码里头

    调用 =code.CNMoney(102.3534)
        
    测试结果:
    1409.50 壹仟肆佰零玖圆伍角整
    6007.14 陆仟零柒圆壹角肆分
    1680.32 壹仟陆佰捌拾圆叁角贰分
    107000.53壹拾万零柒仟圆伍角叁分
    16409.02壹万陆仟肆佰零玖圆零贰分
    325.04 叁佰贰拾伍圆零肆分
    900100001.40玖亿零壹拾万零壹圆肆角整
  • 相关阅读:
    NumPy笔记:运算符(exp,sqrt,square)
    NumPy笔记:常用操作
    php字符操作
    laravel如何实现批量插入
    php中@符号的作用
    laravel如何实现数据的批量插入
    如何在laravel框架中使用阿里云的oss
    laravle如何设置mysql数据表前缀
    thinkphp视图中如何调用并且向控制器传参数
    thinkphp如何隐藏入口文件index.php
  • 原文地址:https://www.cnblogs.com/shuaimeng/p/14898181.html
Copyright © 2011-2022 走看看