| 网站首页 | 新闻 | 新书 | 专家 | 技巧 | 源码作品 | 工具/资源 | 商城 | 风采 | 留言 | 论坛 | 网址 | 承接 | 
您现在的位置: Access/Office中国 >> 技巧 >> Access >> 编程心得绝招 >> 实际编程 >> 文章正文 用户登录 新用户注册
用于将数字换汉字大写数字的函数         ★★★
用于将数字换汉字大写数字的函数
作者:goodorba… 文章来源:Access开发者 点击数: 本日:{$DayHits} 更新时间:2006-10-23 21:52:54
正文:
'用于将数字换汉字大写数字的函数
Function zhh(mrmbze)
Dim S_1 As String
Dim S_2 As String
Dim S_4 As String
Dim s_5 As String
Dim S_6 As String
Dim S_7 As String
Dim I As Integer
Dim tn As Single

S_1 = "零壹贰叁肆伍陆柒捌玖"
S_2 = "仟佰拾万仟佰拾元角分"


Option Compare Database
Option Explicit

Function CWord(myNumber As Double) As String
Dim str1 As String, str2 As String, str3 As String, str4 As String, str5 As String, str6 As String, str7 As String
Dim I As Integer, J As Integer, K As Integer, L As Integer
str1 = "仟佰拾亿仟佰拾万仟佰拾元角分"
str2 = "元角分"
str3 = "零壹贰叁肆伍陆柒捌玖"
str4 = Left(Trim(Format(myNumber, "0.00")), Len(Format(myNumber, "0.00")) - 3) & Right(Trim(Format(myNumber, "0.00")), 2)
str5 = Right(Trim(Format(myNumber, "0.00")), 2)
str6 = Right(str1, Len(str4))
For I = 1 To Len(str4)
K = CDbl(Mid(str4, I, 1))
str7 = str7 & Mid(str3, K + 1, 1) & Mid(str6, I, 1)
Next I
CWord = str7 & "整"
End Function
Function ctest()
MsgBox CWord(120001.03)
End Function



S_4 = Ltrim(Str(Nz(Int(mrmbze * 100))))

If Len(S_4) > 10 And mrmbze > 0 And mrmbze < 99999999.99 Then

  tn = Int(mrmbze * 100) / 100
  
    If mrmbze - tn >= 0.005 Then

       tn = tn + 0.01

    End If

  S_4 = Ltrim(Str(tn * 100))


  
End If

If Len(S_4) > 10 Or mrmbze < 0 Then

zhh = "ERROR!!! The number to be transferred CANNOT be negative and must be less than 99999999.99"

Else

S_4 = String(10 - Len(S_4), " ") + S_4
I = 1
zhh = ""
Do While I <= 10
    s_5 = Mid(S_4, I, 1)
    If s_5 <> " " Then
        S_6 = Mid(S_1, Val(s_5) + 1, 1)
        S_7 = Mid(S_2, I, 1)
        If s_5 = "0" And I <> 4 And I <> 8 Then
            S_7 = ""
            
        End If
        If (Mid(S_4, I, 2) = "00") Or (s_5 = "0" And (I = 4 Or I = 8 Or I = 10)) Then
            S_6 = ""
            
        End If
        zhh = zhh + S_6 + S_7
        
        If Mid(S_4, I, 1) = "0" And Mid(S_4, I + 1, 1) <> "0" And (I = 4 Or I = 8) Then
            zhh = zhh + "零"
        End If
    End If
    I = I + 1
Loop
If s_5 = "0" Then
    zhh = zhh + "整"
End If
End If

If zhh Like "*" & "元零" & "*" & "角" & "*" Then
    zhh = Replace(zhh, "元零", "元")
End If
        

End Function


文章录入:tm    责任编辑:tm 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    专 题 栏 目
    最 新 热 门
    最 新 推 荐
    相 关 文 章
    权限 判断函数
    分类计算余额的函数
    如何判断字符串中包含双
    如何去除公式错误 #N/A 
    在VBA如何使用Excel工作
    如何在自定义函数中实现
    Windows API 函数 for V
    自定义自四舍五入函数
    月初,月末,本月天数的
    取得汉语拼音的函数
    网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)