又要用到数字转化为大写.呵呵,记得先前在网上查了很多资料,有些要么不对,有些要么看起来很复杂的样子,倒不不如自己写一个.因为是在vb6写的,现在移到vb.net 由于vb6和vb.net 对字符串处理方式不同,所以在vb.net 存在着效率不高的现象,不过现在cpu那么快,懒得修改.有空写个vb.net版本.首发qq空间
'数字转换大写 '函数将输入的阿拉伯数字转化为中文数字 Public Function Numtochina(ByVal Num As Double) As String Dim Flag,JiShu As Boolean '每四位数为一级,当同级四位数中只要有一位有效,就需要级数单位,如万,亿 Dim s,s1,s2 As String Dim n,i,tmp As Integer Dim DaXie$(),QuanWei$() s = "零,壹,贰,叁,肆,伍,陆,柒,捌,玖" DaXie = Split(s,",") s = ",拾,佰,仟,万,拾,佰,仟,亿" QuanWei = Split(s,",") '判断整数部分是否大于亿 s = CStr(Num) If InStr(s,".") > 0 Then s1 = Left(s,InStr(s,".") - 1) '整数 s2 = Mid(s,".") + 1) '小数 For i = 1 To Len(s2) s = CInt(Mid(s2,1)) Mid(s2,1) = DaXie(s) Next Else s1 = s End If If Len(s1) > 9 Then MsgBox("不会吧!你的面积居然有超过亿的?可不要搞错哦!",vbInformation) Return "" End If '转化整数 '转换为大写 n = Len(s1) s = "" For i = 1 To n tmp = CInt(Mid(s1,1)) If (tmp) <> 0 Then If Flag Then s = s & "零" & DaXie(tmp) & QuanWei(n - i) Flag = False Else s = s & DaXie(tmp) & QuanWei(n - i) End If '当有一个是非0时,级数为真'过级是清0 If (n - i) Mod 4 = 0 Then JiShu = False Else JiShu = True End If Else If (n - i) Mod 4 = 0 Then If JiShu Then s = s & QuanWei(n - i) JiShu = False Flag = False End If Else Flag = True End If End If Next If Len(s2) = 0 Then Numtochina = s Else Numtochina = s & "点" & s2 End If End Function