有没有能把数字金额转为英文的函数?

jingchu 2004-03-23 12:03:34
例如:
7000——seven thousand
有没有这样的现成函数?
...全文
162 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
jingchu 2004-03-26
  • 打赏
  • 举报
回复
谢谢vbman2003(家人)和openforever(++)的代码,我自己写好啦,呵呵,很开心:)
虽然用了一个下午,但是,能得到结果这是最大的回报了。
ganzhiruogy 2004-03-23
  • 打赏
  • 举报
回复
自己写不难啊!
或找个转汉字大写的学习一下算法,改改咯!
flyingscv 2004-03-23
  • 打赏
  • 举报
回复
mark
等好心人的代码 :)
Wat5 2004-03-23
  • 打赏
  • 举报
回复
没有,自己写一个吧
vbman2003 2004-03-23
  • 打赏
  • 举报
回复
将数字转化为大写金额
Dim str_Text As String
Dim str_Data As String
Dim str_DX As String
Dim DX_Odd() As String
Dim Dw() As String
Dim a As Variant
Dim M As String
Dim i As Long
Dim j As Long
'检查输入内容
If Trim(Text1.Text) = "" Then
MsgBox "请输入数字"
Text1.SetFocus
Exit Sub
End If
If Not IsNumeric(Trim(Text1.Text)) Then
MsgBox "不允许输入文本,请输入数字"
Text1.SetFocus
Exit Sub
End If
If CDbl(Trim(Text1.Text)) >= 100000 Then
MsgBox "输入数字过大,系统不允许操作,请重新输入"
Text1.SetFocus
Exit Sub
End If
'格式化文本
Text1.Text = Format(Trim(Text1.Text), "##0.00" & "元")
'数据格式转换
str_Text = Trim(Text1.Text)
a = Split(str_Text, "元") '获得以"元"分隔的文本组成数组(去除“元”)
str_Data = CStr(a(0) * 100) '去除小数点
i = Len(str_Data) '获得文本长度
Select Case i '根据文本长度选择单位
Case 1
ReDim Dw(1)
Dw(1) = "分"
Case 2
ReDim Dw(2)
Dw(1) = "角"
Dw(2) = "分"
Case 3
ReDim Dw(3)
Dw(1) = "元"
Dw(2) = "角"
Dw(3) = "分"
Case 4
ReDim Dw(4)
Dw(1) = "拾"
Dw(2) = "元"
Dw(3) = "角"
Dw(4) = "分"
Case 5
ReDim Dw(5)
Dw(1) = "百"
Dw(2) = "拾"
Dw(3) = "元"
Dw(4) = "角"
Dw(5) = "分"
Case 6
ReDim Dw(6)
Dw(1) = "仟"
Dw(2) = "佰"
Dw(3) = "拾"
Dw(4) = "元"
Dw(5) = "角"
Dw(6) = "分"
Case 7
ReDim Dw(7)
Dw(1) = "万"
Dw(2) = "仟"
Dw(3) = "佰"
Dw(4) = "拾"
Dw(5) = "元"
Dw(6) = "角"
Dw(7) = "分"
End Select
For j = 1 To i '将str_Data中的阿拉伯数字转为中文数字
ReDim DX_Odd(j)
DX_Odd(j) = Right(Left(str_Data, j), 1)
Select Case DX_Odd(j)
Case 0
M = "零"
Case 1
M = "壹"
Case 2
M = "贰"
Case 3
M = "叁"
Case 4
M = "肆"
Case 5
M = "伍"
Case 6
M = "陆"
Case 7
M = "柒"
Case 8
M = "捌"
Case 9
M = "玖"
End Select
str_DX = str_DX & M & Dw(j) '添加数字和单位
Next j
'显示中文货币格式
Text2.Text = str_DX
unknow_123 2004-03-23
  • 打赏
  • 举报
回复
mark
openforever 2004-03-23
  • 打赏
  • 举报
回复

'将数字转化为大写金额.
'函数:CurToHz
'参数:Number 要转化的金额,Divvy 返回值分隔符(默认为"")
'返回值:String.[成功,则返回转化后的汉字金额,失败,返回 "ERR")
'例子:
Public Function CurToHz(ByVal Number As Double, Optional Divvy As String = "") As String
Dim Number_string As String
Dim Dot_pos As Integer
Dim Result_string As String
Dim Is_Zero As Boolean
Dim This_Class_NoNumber As Boolean
Dim Dig_string As String
Dim Integer_Len As Integer, Decimal_Len As Integer
Dim Class_val As Integer
Dim Digit() As Variant
Dim Digit_Format() As Variant
Dim Class() As Variant
Dim I As Long, N As Long
'/---------------------------------------------------------------------------
Digit = Array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "元", "角", "分")
Digit_Format = Array("", "拾", "佰", "仟")
Class = Array("", "万", "亿", "兆")

Is_Zero = False
Number_string = CStr(Number)
Dot_pos = InStr(Number_string, ".")

If Dot_pos = 0 Then
'/ 该数为整数
Integer_Len = Len(Number_string)
If Integer_Len Mod 4 = 0 Then
Class_val = Int(Integer_Len / 4) - 1
Else
Class_val = Int(Integer_Len / 4)
End If
For I = 1 To Integer_Len
If (Integer_Len - I - Class_val * 4) = -1 Then
If This_Class_NoNumber = False Then
Result_string = Result_string & Class(Class_val) & Divvy
End If
Class_val = Class_val - 1
Is_Zero = False
This_Class_NoNumber = True
End If
Dig_string = Mid$(Number_string, I, 1)
If CInt(Dig_string) = 0 Then
Is_Zero = True
Else
If Is_Zero = True Then
Result_string = Result_string & Digit(0) & Divvy
End If
Result_string = Result_string & Digit(Dig_string) & Divvy
If (Integer_Len - I) Mod 4 <> 0 Then
Result_string = Result_string & Digit_Format(((Integer_Len - I) Mod 4)) & Divvy
End If
Is_Zero = False
This_Class_NoNumber = False
End If
Next
Result_string = Result_string & Divvy & Digit(10)
Else
'/ 该处为整数部分
Integer_Len = Dot_pos - 1
If Integer_Len Mod 4 = 0 Then
Class_val = Int(Integer_Len / 4) - 1
Else
Class_val = Int(Integer_Len / 4)
End If
For I = 1 To Integer_Len
If (Integer_Len - I - Class_val * 4) = -1 Then
If This_Class_NoNumber = False Then
Result_string = Result_string & Class(Class_val) & Divvy
End If
Class_val = Class_val - 1
Is_Zero = False
This_Class_NoNumber = True
End If
Dig_string = Mid$(Number_string, I, 1)
If CInt(Dig_string) = 0 Then
Is_Zero = True
Else
If Is_Zero = True Then
Result_string = Result_string & Digit(0) & Divvy
End If
Result_string = Result_string & Digit(Dig_string) & Divvy
If (Integer_Len - I) Mod 4 <> 0 Then
Result_string = Result_string & Digit_Format(((Integer_Len - I) Mod 4)) & Divvy
End If
Is_Zero = False
This_Class_NoNumber = False
End If
Next
If Integer_Len = 0 Then '纯小数
Result_string = Result_string & Digit(0) & Divvy
End If
Result_string = Result_string & Digit(10) & Divvy
'/该处为小数部分
For I = Dot_pos + 1 To Len(Number_string)
N = N + 1 '小数点后两位.
If N < 3 Then Result_string = Result_string & Digit(Mid$(Number_string, I, 1)) & Divvy & Digit(10 + N) & Divvy
Next
End If
CurToHz = Result_string
End Function

自己改改试试
jingchu 2004-03-23
  • 打赏
  • 举报
回复
郁闷,有没有现成的嘛?:(

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧