水晶报表中如何创建和使用函数请参考:【水晶报表内功心法】--公式、函数与运行时总计
函数使用Basic语法
'#############################################################################
'货币转换为中文汉字表述
'
'函数名称:CNMoney
'参数:ls
'返回值:转换后的字符串
'
'整理人:阿泰
'版本历史
'2010-04-20:首次编译,修正0参数,修正小于10的值不能正常显示的BUG
'
'本文函数来源于 feng442624978,原帖地址:
'http://topic.csdn.net/u/20100303/15/0f0ceca7-d29d-4269-b0f5-17ea09d0f139
'#############################################################################
Function CNMoney(ls As Number) As String
Dim dx_sz As String
Dim dx_dw As String
Dim str_int As String
Dim str_dec As String
Dim dx_str As String
Dim fu As String
Dim a As String
Dim b As String
Dim c As String
Dim d As String
Dim b2 As String
Dim num_int As Number
Dim num_dec As Number
Dim len_int As Number
Dim i As Number
Dim a_int As Number
Dim pp As Number
dx_sz = "零壹贰叁肆伍陆柒捌玖"
dx_dw = "万仟佰拾亿仟佰拾万仟佰拾圆"
If ls = 0 Then
CNMoney = "零圆整"
Exit Function
End If
If ls < 0 Then
ls = Abs(ls)
fu = "负"
Else
fu = ""
End If
dx_str = CStr(ls)
dx_str = Replace(dx_str, "¥", "")
dx_str = Replace(dx_str, ",", "")
If (ls >= 0) And (ls < 1) Then dx_str = "0" + dx_str
pp = InStr(dx_str, ".")
If pp > 0 Then
str_int = Mid(dx_str, 1, InStr(dx_str, ".") - 1)
Else
str_int = dx_str
End If
num_int = tonumber(str_int)
If (ls > 0) And (ls < 1) Then
num_dec = ls * 100
Else
num_dec = (ls - num_int) * 100
End If
str_dec = totext(num_dec)
str_dec = Replace(str_dec, "¥", "")
len_int = Len(str_int)