问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

vb程序设计 将阿拉伯数字转换成大写人民币金额 这是小弟的VB结课设计...

发布网友 发布时间:2022-05-12 19:49

我来回答

3个回答

热心网友 时间:2022-04-27 17:15

Private Sub Form_Load()
Check1.Value = 0
Check2.Value = 1
End Sub
'参数一为数字
'参数二为是不是返回人民币大写
'参数三为带有十百千等单位
'参数四为设置小数点后面的位数,默认为4
'使用方法是
't = GetChinaNum(20005.000436, , , 7) '返回 “二千零五点零零零四三六”
't = GetChinaNum(2005.436, True, , 7) '返回“贰仟零伍元肆角肆分”
't = GetChinaNum(2005.436, , True, 7) '返加“二零零五点四三六”
'原作者:thinkeasy 出处:中国IT动力 改写: 雪国浪子

Function GetChinaNum(otherNum As Double, Optional isRMB As Boolean, Optional numOption As Boolean, Optional dotNum As Integer) As String
On Error Resume Next
Num = Trim(Str(Int(otherNum)))
'-------------------------------------------------------
'判断是否需要转化为人民币大写,给出两种情况下的中文单位
If isRMB Then
numwei = "拾佰仟万拾佰仟亿拾佰仟"
numshu = "零壹贰叁肆伍陆柒捌玖拾"
Else
numwei = "十百千万十百千亿十百千"
numshu = "零一二三四五六七*十"
End If
'-------------------------------------------------------
'如果数字大于等于9并且小于20,则数字应转化为“十*”
If otherNum < 20 And otherNum >= 10 Then
Num = Right(Num, 1)
GetChinaNum = Left(numwei, 1)
End If
'-------------------------------------------------------
'转化程序开始
For i = 1 To Len(Num)
bstr = Mid(Num, i, 1)
If numOption Then
GetChinaNum = GetChinaNum + Mid(numshu, Val(bstr) + 1, 1)
If bstr = "0" Then
If Mid(numwei, Len(Num) - i, 1) = "万" Or Mid(numwei, Len(Num) - i, 1) = "亿" Then
Do While Right(GetChinaNum, 1) = "零"
GetChinaNum = Left(GetChinaNum, Len(GetChinaNum) - 1)
Loop
GetChinaNum = GetChinaNum + Mid(numwei, Len(Num) - i, 1)
End If
Else
GetChinaNum = GetChinaNum + Mid(numwei, Len(Num) - i, 1)
End If
GetChinaNum = Replace(GetChinaNum, "零零", "零")
Else
GetChinaNum = GetChinaNum + Mid(numshu, Val(bstr) + 1, 1)
End If
Next i
'-------------------------------------------------------
'判断是否需要显示数字单位
If numOption = False Then
Do While Right(GetChinaNum, 1) = "零"
GetChinaNum = Left(GetChinaNum, Len(GetChinaNum) - 1)
Loop
End If
'-------------------------------------------------------
'判断是否需要显示人民币大写,如果需要,进一步转化
If isRMB Then
numrmb = "元角分"
GetChinaNum = GetChinaNum + Mid(numrmb, 1, 1)
If Val(Num) <> otherNum Then
Num = Trim(Str(Round(otherNum - Val(Num), 2)))
For i = 2 To Len(Num)
bstr = Mid(Num, i, 1)
GetChinaNum = GetChinaNum + Mid(numshu, Val(bstr) + 1, 1) + Mid(numrmb, i, 1)
Next i
Else
GetChinaNum = GetChinaNum + "整"
End If
Else
If Val(Num) <> otherNum Then
Num = Trim(CStr(Round(otherNum - Val(Num), dotNum)))
If GetChinaNum = "" Then GetChinaNum = "零"
GetChinaNum = GetChinaNum + "点"
For i = 2 To Len(Num)
bstr = Mid(Num, i, 1)
GetChinaNum = GetChinaNum + Mid(numshu, Val(bstr) + 1, 1)
Next i
End If
End If
End Function
'转化数字的 CommandButton
Private Sub Command1_Click()
Dim Num As Double, dot As Integer
Dim Chk_RMB As Boolean, Chk_Unit As Boolean
Dim ChResult As String
If Text1.Text = "" Then
Label5.Caption = "请输入需要转化的阿拉伯数字。"
Else
Num = Val(Text1.Text)
If Text2.Text = "" Then
Text2.Text = "4"
End If
dot = Val(Text2.Text)
Chk_RMB = CBool(Check1.Value)
Chk_Unit = CBool(Check2.Value)
ChResult = GetChinaNum(Num, Chk_RMB, Chk_Unit, dot)
Label5.Caption = ChResult
End If
End Sub

'复原输入框的 CommandButton
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = "4"
Check1.Value = 0
Check2.Value = 1
Label5.Caption = ""
End Sub

'判TextBox1中输入的是否是数字或小数点
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (Chr(KeyAscii) > "9" Or Chr(KeyAscii) < "0") And (Chr(KeyAscii) <> ".") And (KeyAscii <> 8) Then
KeyAscii = 0
Label5.Caption = "只允许输入数字或小数点"
End If
End Sub

热心网友 时间:2022-04-27 18:33

Private Sub Command2_Click()
Unload Me
End Sub

'转换函数
Function Up(Dxs As String) As String
'检测为空时
If Trim(Dxs) = "" Then
MsgBox "没有数字,不能转换!", vbOKOnly + 32
Exit Function
End If
Dim Sw As Integer, SzP As Integer, SzUp As Integer, TempStr As String, DXStr As String
Sw = Len(Trim(Dxs))
SzP = InStr(1, Trim(Dxs), ".")
If SzP = 0 Then
Dim i As Integer
For i = 1 To Sw
TempStr = Right(Trim(Dxs), i)
TempStr = Left(TempStr, 1)
TempStr = Converts(TempStr)
Select Case i
Case 1
If TempStr = "零" Then
TempStr = "元"
Else
TempStr = TempStr + "元"
End If
Case 2
If TempStr = "零" Then
TempStr = "零"
Else
TempStr = TempStr + "拾"
End If
Case 3
If TempStr = "零" Then
TempStr = "零"
Else
TempStr = TempStr + "佰"
End If
Case 4
If TempStr = "零" Then
TempStr = "零"
Else
TempStr = TempStr + "仟"
End If
Case 5
If TempStr = "零" Then
TempStr = "万"
Else
TempStr = TempStr + "万"
End If
Case 6
If TempStr = "零" Then
TempStr = "零"
Else
TempStr = TempStr + "拾"
End If
Case 7
If TempStr = "零" Then
TempStr = "零"
Else
TempStr = TempStr + "佰"
End If
Case 8
If TempStr = "零" Then
TempStr = "零"
Else
TempStr = TempStr + "仟"
End If
Case 9
If TempStr = "零" Then
TempStr = "亿"
Else
TempStr = TempStr + "亿"
End If
End Select
Dim TempA As String
TempA = Left(Trim(DXStr), 1)
If TempStr = "零" Then
Select Case TempA
Case "零"
DXStr = DXStr
Case "元"
DXStr = DXStr
Case "万"
DXStr = DXStr
Case "亿"
DXStr = DXStr
Case Else
DXStr = TempStr + DXStr
End Select
Else
DXStr = TempStr + DXStr
End If
Next
Else
For i = 1 To SzP - 1
TempStr = Right(Trim(Dxs), i + (Sw - SzP + 1))
TempStr = Left(TempStr, 1)
TempStr = Converts(TempStr)
Select Case i
Case 1
If TempStr = "零" Then
TempStr = "元"
Else
TempStr = TempStr + "元"
End If
Case 2
If TempStr = "零" Then
TempStr = "零"
Else
TempStr = TempStr + "拾"
End If
Case 3
If TempStr = "零" Then
TempStr = "零"
Else
TempStr = TempStr + "佰"
End If
Case 4
If TempStr = "零" Then
TempStr = "零"
Else
TempStr = TempStr + "仟"
End If
Case 5
If TempStr = "零" Then
TempStr = "万"
Else
TempStr = TempStr + "万"
End If
Case 6
If TempStr = "零" Then
TempStr = "零"
Else
TempStr = TempStr + "拾"
End If
Case 7
If TempStr = "零" Then
TempStr = "零"
Else
TempStr = TempStr + "佰"
End If
Case 8
If TempStr = "零" Then
TempStr = "零"
Else
TempStr = TempStr + "仟"
End If
Case 9
If TempStr = "零" Then
TempStr = "亿"
Else
TempStr = TempStr + "亿"
End If
Case Else
'超过999999999时自动删除
TempStr = ""
End Select
TempA = Left(Trim(DXStr), 1)
If TempStr = "零" Then
Select Case TempA
Case "零"
DXStr = DXStr
Case "元"
DXStr = DXStr
Case "万"
DXStr = DXStr
Case "亿"
DXStr = DXStr
Case Else
DXStr = TempStr + DXStr
End Select
Else
DXStr = TempStr + DXStr
End If
Next
'计算小数
Dim DxstrX As String, XStr As String
XStr = Right(Trim(Dxs), Sw - SzP)
For i = 1 To Sw - SzP
TempStr = Left(XStr, i)
TempStr = Right(TempStr, 1)
TempStr = Converts(TempStr)
Select Case i
Case 1
If TempStr = "零" Then
TempStr = ""
Else
TempStr = TempStr + "角"
End If
Case 2
If TempStr = "零" Then
TempStr = ""
Else
TempStr = TempStr + "分"
End If
Case Else
'超过两位小数时,自动删除
TempStr = ""
End Select
DxstrX = DxstrX + TempStr
Next
DXStr = DXStr + DxstrX
End If
Up = DXStr
End Function

Function Converts(NumStr As String) As String
Select Case Val(NumStr)
Case 0
Converts = "零"
Case 1
Converts = "壹"
Case 2
Converts = "贰"
Case 3
Converts = "叁"
Case 4
Converts = "肆"
Case 5
Converts = "伍"
Case 6
Converts = "陆"
Case 7
Converts = "柒"
Case 8
Converts = "捌"
Case 9
Converts = "玖"
End Select
End Function
Function NumberTrue(keyNumber As Integer, NumberStr As TextBox) As Boolean
'转入退格键时
If keyNumber = 8 Then
If Len(NumberStr.Text) > 0 Then
NumberStr.Text = Left(NumberStr.Text, Len(NumberStr.Text) - 1)
NumberStr.SelStart = Len(NumberStr.Text)
NumberStr.SelLength = 0
NumberTrue = True
Exit Function
End If
End If
If keyNumber >= 46 And keyNumber <= 57 And keyNumber <> 47 Then
NumberTrue = True
Else
NumberTrue = False
End If
End Function

Private Sub Convert_Click()
Label1.Caption = Up(Text1.Text)
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If NumberTrue(KeyAscii, Text1) = False Then
KeyAscii = 0
End If

End Sub

热心网友 时间:2022-04-27 20:08

不知道为什么,说是有问题,不让发表,可能给钱有关系吧!
发到了空间!
看下面 ^_^

参考资料:http://hi.baidu.com/yiqnypl/blog/item/183c7b4f32787c2eafc3ab9e.html

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
iOS 16.1.1值得更新升级吗 ios16.1.1正式版建议更新吗 iOS 16.1.1修复了哪些问题 ios16.1.1值得更新吗?ios 16.1.1新增内容及更新建议 iPhone 12升级iOS 16.1.1之后好用吗 iOS 16.1.1更新内容介绍 iOS 16.1正式版新增了哪些新功能?iOS 16.1正式版值得升级吗? ios 16.1正式版解决了哪些问题和BUG ...森先生是他“最好的老师” 你喜欢这样的老师吗? ... 你喜欢怀特森这样老师吗?说说你的看法.250字 你好我的包裹也是从荷兰邮政寄出来的,cc007951779nl,现在什么情况了,谢谢 苹果平板iPad4 序列号是DMPKRXOBF183 B前面O是大写英文字母 是假的吗? 183.5元大写怎么写 谁知道2008奥运会资料 ??? 壹佰捌拾叁元 是什么意思? 北京市维凯安润滑油商店怎么样? 深圳奇智讯飞视觉科技有限公司怎么样? 围绕人文、地理、体育、军事、科技、禁烟、环保、科学幻想、青奥宣传,做电脑绘画或电脑动画或网业制作 胰岛素泵多少钱? 深圳维凯仕教育技术有限公司怎么样? 广西南宁维凯电子科技有限公司怎么样? 宁波维凯网络科技有限公司怎么样? 杭州维凯科技有限公司怎么样? 江苏维凯科技股份有限公司怎么样? ...预览显示正常,但打印的时候只能打印一半,怎么解决? 给我100个脑筋急转弯!! 帮我多出几个脑筋急转弯吧? 怎样区别羽毛球拍的好坏? CSS如何设置div半透明效果 羽毛球拍牌子和型号问题? 嗯咯是哪个大写的读音 谁能解释一下excel大写人民币公式的含义啊? 蔡徐坤登上法国版《时装》封面!蔡徐坤的时尚感是否已经获得国际认可? 老婆不孕我提离婚,后来发现问题出现在我身上。我是不是错了? 华为荣耀V9华为视频无法正常播放观看怎么办? Honor9怎么全屏看华为视频? Honor9在华为视频中怎么全屏观看? 贝妮熊黑咖啡减肥吗? 雀巢咖啡和贝妮熊咖啡那个好? html输入框只有左边可以点击输入? HTML 如图样式的输入框怎么写 中学生怎样在手机上快速赚到3000元 如何赚钱,如何在一天甚至几个小时内赚取3000元 有什么方法一个月用手机赚3000元,无论什么代价,除犯法 如何赚钱,如何在一天甚至几个小时内赚取3000元? 手机上一个月赚3000行吗 css div 实现 一个小层的背景是半透明的,但上面的文字是不透明的? 同级单位不配合工作怎么发函 给平级单位说明我单位片区隶属关系用什么文写好?情况说明也不合适,报告也不合适,急求,谢谢! 小米MAX有录屏功能吗