| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1987 人关注过本帖
标题:最少代码把数字转换成人民币大写
只看楼主 加入收藏
singlion
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2007-6-16
收藏
 问题点数:0 回复次数:7 
最少代码把数字转换成人民币大写
Dim num As Long, num_t As Long, i As Long, l As Long
Dim rmb As String, rmb_char As String, rmb_weight As String
l = Len(Text1.Text)
For i = l To 1 Step -1
num_t = num
num = Mid(Text1.Text, l - i + 1, 1)
If num_t = num And num = 0 Then GoTo ooo

rmb_char = IIf(num = 0, "零", Choose(num, "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"))
rmb_weight = Choose(i, "", "拾", "佰", "仟", "萬", IIf(Mid(Text1.Text, l - i + 2, 1) = 0, "拾萬", "拾"), "佰", "仟", "萬", "亿", IIf(Mid(Text1.Text, l - i + 2, 1) = 0, "拾亿", "拾"), "佰", "仟", "萬")
rmb = rmb & rmb_char & IIf(num = 0, "", rmb_weight)
ooo:
Next i
MsgBox rmb
搜索更多相关主题的帖子: num 人民币 数字 Long 
2007-11-15 12:54
simpson
Rank: 3Rank: 3
等 级:论坛游民
威 望:7
帖 子:863
专家分:17
注 册:2006-11-16
收藏
得分:0 

有bug
1.个位为0时 最后都会有个"零"字


2.小数不识别


全国最大的 Java专业电子书免费分享[url]http:///in.asp?id=xrmao[/url]
2007-11-15 13:20
朗朗
Rank: 1
等 级:新手上路
帖 子:235
专家分:0
注 册:2007-10-2
收藏
得分:0 
以下是引用simpson在2007-11-15 13:20:35的发言:

有bug
1.个位为0时 最后都会有个"零"字


2.小数不识别

你给来个没有BUG的吧

2007-11-15 17:05
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
收藏
得分:0 

微软也做不到没bug的东西哦.


我的msn: myfend@
2007-11-15 17:19
simpson
Rank: 3Rank: 3
等 级:论坛游民
威 望:7
帖 子:863
专家分:17
注 册:2006-11-16
收藏
得分:0 

在他基础上改的有点不好

有空重新做个简洁点的给你看


Private Sub Command1_Click()
Dim num As Long, num_t As Long, i As Long, l As Long, s As Long
Dim rmb As String, rmb_char As String, rmb_weight As String
l = Len(Text1.Text)
s = InStr(1, Text1.Text, ".", vbTextCompare)
If s = 0 Then
For i = l To 1 Step -1
num_t = num
num = Mid(Text1.Text, l - i + 1, 1)
If num_t = num And num = 0 Then GoTo ooo1

rmb_char = IIf(num = 0, "零", Choose(num, "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"))
rmb_weight = Choose(i, "", "拾", "佰", "仟", "萬", IIf(Mid(Text1.Text, l - i + 2, 1) = 0, "拾萬", "拾"), "佰", "仟", "萬", "亿", IIf(Mid(Text1.Text, l - i + 2, 1) = 0, "拾亿", "拾"), "佰", "仟", "萬")
rmb = rmb & rmb_char & IIf(num = 0, "", rmb_weight)
ooo1:
Next i
rmb = IIf(Mid(rmb, Len(rmb), Len(rmb)) = "零", Mid(rmb, 1, Len(rmb) - 1), rmb)
MsgBox rmb
Exit Sub
Else
For i = s - 1 To 1 Step -1
num_t = num
num = Mid(Text1.Text, s - i, 1)

If num_t = num And num = 0 Then GoTo ooo2

rmb_char = IIf(num = 0, "零", Choose(num, "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"))
rmb_weight = Choose(i, "", "拾", "佰", "仟", "萬", IIf(Mid(Text1.Text, l - i + 2, 1) = 0, "拾萬", "拾"), "佰", "仟", "萬", "亿", IIf(Mid(Text1.Text, l - i + 2, 1) = 0, "拾亿", "拾"), "佰", "仟", "萬")
rmb = rmb & rmb_char & IIf(num = 0, "", rmb_weight)
ooo2:
Next i
rmb = IIf(Mid(rmb, Len(rmb), Len(rmb)) = "零", Mid(rmb, 1, Len(rmb) - 1), rmb)

If s <> l Then rmb = rmb & "点"
For i = l To s + 1 Step -1
num = Mid(Text1.Text, s - i + 1 + l, 1)
rmb_char = IIf(num = 0, "零", Choose(num, "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"))
rmb = rmb & rmb_char
Next i
MsgBox rmb
Exit Sub
End If
End Sub

[此贴子已经被作者于2007-11-15 18:56:39编辑过]


全国最大的 Java专业电子书免费分享[url]http:///in.asp?id=xrmao[/url]
2007-11-15 17:37
multiple1902
Rank: 8Rank: 8
等 级:贵宾
威 望:42
帖 子:4881
专家分:671
注 册:2007-2-9
收藏
得分:0 

确实……楼上这个代码不中看

2007-11-15 18:02
slore
Rank: 5Rank: 5
等 级:贵宾
威 望:16
帖 子:1108
专家分:0
注 册:2005-7-1
收藏
得分:0 
Private Sub Command1_Click()
Print 大写转换("1442778565.93")
End Sub

Public Function
大写转换(ByVal NumStr As String) As String
    Dim
As String, As Integer, i As Integer

   
= ReplaceEx(NumStr, "0", "", "1", "", "2", "", "3", "", "4", "", "5", "", "6", "", "7", "", "8", "", "9", "")
   
Pos = InStr(NumStr, ".")
   
If Pos = 0 Then
        
= Len(NumStr)
   
Else
        
= Pos - 1
    End If
    For
i = To 1 Step - 1
        Mid(数, i * 2, 1) = Mid("圆拾佰仟万拾佰仟亿拾佰仟万", 长 - i + 1, 1)
   
Next
    If
Pos > 0 Then
        
NumStr = Replace(数, ".", Empty, Pos * 2 - 1)
        
= Mid(数, 1, (Pos - 1) * 2)
        
Select Case Len(NumStr)
            
Case 4
                Mid(NumStr, 2, 1) = ""
                Mid(NumStr, 4, 1) = ""
            Case 2
                Mid(NumStr, 2, 1) = ""
        End Select
    Else
        
NumStr = Empty
    End If
   
= ReplaceEx(& NumStr, "零分", Empty, "零角", "", "零拾", "", "零佰", "", "零仟", "", "零零零", "", "零零", "", "零亿", "亿", "零万", "", "零圆", "", "亿万", "亿")
   
大写转换 =
End Function

Public Function
ReplaceEx(InputStr As String, ParamArray 参数() As Variant) As String
Dim
tmp As Long
ReplaceEx = InputStr
    For tmp = 0 To (UBound(参数) - 1) Step 2
        ReplaceEx = Replace(ReplaceEx, 参数(tmp), 参数(tmp + 1))
   
Next
End Function

快上课了……
2007-11-22 22:13
skdyu
Rank: 1
等 级:新手上路
帖 子:38
专家分:0
注 册:2007-3-26
收藏
得分:0 
看看,学习学习,谢谢
2012-11-30 14:25
快速回复:最少代码把数字转换成人民币大写
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.057427 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved