设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 2547|回复: 4
打印 上一主题 下一主题

[其它] [原创]阿拉伯数字转大写(用在财务金额的转换)

[复制链接]
跳转到指定楼层
1#
发表于 2006-3-23 23:12:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
添加过程,函数如下:

Public Function Num2Str(num As Double) As String
If num >= 1000000000 Then Exit Function
    Dim temp1 As String
    Dim temp2 As String
    Dim temp3 As String
    x = 0
    temp1 = "零壹贰叁肆伍陆柒捌玖"
    temp2 = "元拾佰仟万拾佰仟亿"
    temp3 = "角分"
    ss = Round(num, 2)
    s = Split(ss, ".")
    ss = Trim$(s(0))
For i = 1 To Len(ss)
n = Val(Mid$(ss, i, 1)) + 1

Num2Str = Num2Str & Mid$(temp1, n, 1) & Mid$(temp2, Len(ss) - i + 1, 1)

If Right(Num2Str, 2) = "零亿" Then Num2Str = Left(Num2Str, Len(Num2Str) - 2) & "亿"
If Right(Num2Str, 2) = "零万" Then Num2Str = Left(Num2Str, Len(Num2Str) - 2) & "万"
If Right(Num2Str, 2) = "零仟" Then Num2Str = Left(Num2Str, Len(Num2Str) - 2)
If Right(Num2Str, 2) = "零元" Then Num2Str = Left(Num2Str, Len(Num2Str) - 2) & "元"
If Right(Num2Str, 2) = "零佰" Then Num2Str = Left(Num2Str, Len(Num2Str) - 2)
If Right(Num2Str, 2) = "零拾" Then Num2Str = Left(Num2Str, Len(Num2Str) - 2)

Next i

For i = 1 To Len(Num2Str)
If Mid(Num2Str, i, 1) = "仟" And Mid(Num2Str, i + 2, 1) = "万" Then Num2Str = Left(Num2Str, i) & "零" & Mid(Num2Str, i + 1, Len(Num2Str) - i)
If Mid(Num2Str, i, 1) = "仟" And Mid(Num2Str, i + 2, 1) = "拾" Then Num2Str = Left(Num2Str, i) & "零" & Mid(Num2Str, i + 1, Len(Num2Str) - i)
If Mid(Num2Str, i, 1) = "仟" And Mid(Num2Str, i + 2, 1) = "元" Then
If Mid(Num2Str, i + 1, 1) = "万" Then
Else
Num2Str = Left(Num2Str, i) & "零" & Mid(Num2Str, i + 1, Len(Num2Str) - i)
End If
End If
If Mid(Num2Str, i, 1) = "佰" And Mid(Num2Str, i + 2, 1) = "元" Then
If Mid(Num2Str, i + 1, 1) = "万" Then
Else
Num2Str = Left(Num2Str, i) & "零" & Mid(Num2Str, i + 1, Len(Num2Str) - i)
End If
End If
If Mid(Num2Str, i, 1) = "万" And Mid(Num2Str, i + 2, 1) = "佰" Then Num2Str = Left(Num2Str, i) & "零" & Mid(Num2Str, i + 1, Len(Num2Str) - i)
If Mid(Num2Str, i, 1) = "万" And Mid(Num2Str, i + 2, 1) = "拾" Then Num2Str = Left(Num2Str, i) & "零" & Mid(Num2Str, i + 1, Len(Num2Str) - i)
If Mid(Num2Str, i, 1) = "万" And Mid(Num2Str, i + 2, 1) = "元" Then Num2Str = Left(Num2Str, i) & "零" & Mid(Num2Str, i + 1, Len(Num2Str) - i)
If Mid(Num2Str, i, 1) = "佰" And Mid(Num2Str, i + 2, 1) = "万" Then Num2Str = Left(Num2Str, i) & "零" & Mid(Num2Str, i + 1, Len(Num2Str) - i)
If Mid(Num2Str, i, 1) = "亿" And Mid(Num2Str, i + 2, 1) = "拾" Then Num2Str = Left(Num2Str, i) & "零" & Mid(Num2Str, i + 1, Len(Num2Str) - i)
If Mid(Num2Str, i, 1) = "亿" And Mid(Num2Str, i + 2, 1) = "佰" Then Num2Str = Left(Num2Str, i) & "零" & Mid(Num2Str, i + 1, Len(Num2Str) - i)
If Mid(Num2Str, i, 1) = "亿" And Mid(Num2Str, i + 2, 1) = "万" Then Num2Str = Left(Num2Str, i) & "零" & Mid(Num2Str, i + 1, Len(Num2Str) - i)

Next i


If UBound(s) >= 1 Then
ss = Trim$(s(1))
For i = 1 To 2
n = Val(Mid$(ss, i, 1))
If n <> 0 Then
Num2Str = Num2Str & Mid$(temp1, n + 1, 1) & Mid$(temp3, i, 1)
Else
If Right$(Num2Str, 1) <> "零" Then Num2Str = Num2Str & "零"
End If
Next i
If Right$(Num2Str, 1) = "零" Then Num2Str = Left$(Num2Str, Len(Num2Str) - 1)
Else
Num2Str = Num2Str & "整"
End If

End Function



使用如下:

Text52.Value = Num2Str(Text43.Value)
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2006-11-25 21:47:00 | 只看该作者
翻跟斗风格
3#
发表于 2006-11-26 05:28:00 | 只看该作者
不错哦!!!!
4#
发表于 2010-3-3 17:17:41 | 只看该作者
感谢之情 无法形容 谢谢啊
5#
发表于 2010-3-3 21:04:22 | 只看该作者
很实用,谢谢分享!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-11 00:49 , Processed in 0.088437 second(s), 29 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表