.net rdlc 自定义函数"把数字转换为大写中文"

前端之家收集整理的这篇文章主要介绍了.net rdlc 自定义函数"把数字转换为大写中文"前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

在.net平台的rdlc中,可以使用自定义方法来扩充报表功能,比如常见的 ”把数字转换为大写中文

网上找了很久发现这篇不错 原文

后来细心测试发现存在一个bug,原文也有人评论有bug,可是原作者一直没更正代码

研究了一下代码,自行修改如下:直接上代码(用 vb 写的,红色部分为修改代码

Function CNMoney(money As Double) As String
Dim str_Money = money.ToString()
Dim str_China As [String]() = {"分","角","元","拾","佰","仟",_
"万","亿",_
"佰","兆","仟"}
Dim str_Number As [String]() = {"零","壹","贰","叁","肆","伍",_
"陆","柒","捌","玖"}
Dim M As [String] = ""
Dim mark As Integer
''不正常数据
If InStr(Right(str_Money,2),".") > 0 Then
mark = 0
Else
mark = 1
End If

Dim isPoint As Boolean = False
If str_Money.IndexOf(".") <> -1 Then
str_Money = str_Money.Remove(str_Money.IndexOf("."),1)
isPoint = True
End If
For i As Integer = str_Money.Length To 1 Step -1
Dim MyData As Integer = Convert.ToInt16(str_Money(str_Money.Length - i).ToString())
M += str_Number(MyData)
If isPoint = True Then
M += str_China(i - mark) Else M += str_China(i + 1) End If Next Return M End Function

原文链接:https://www.f2er.com/vb/257977.html

猜你在找的VB相关文章