|
本帖最后由 qy1219no2 于 2014-12-11 21:05 编辑
看到现在金额中文大小写已经无法阻止人类的进攻了,最近开始流行数字转英文大写了,由于时间紧凑,简单弄了一个VBA自定义函数,现贴上来,请各路大侠不吝赐教
目前仅支持正数,且不能超过1万亿!
主体函数是albToEn()
- Function albToEn(n As Double) As String
- Dim c1$, c2$, cNum$, nZs$
- cNum = Format(n, "#,##0.00")
- nZs = Split(cNum, ".")(0)
- nXs = Split(cNum, ".")(1)
- If Val(nZs) = 0 Then
- c1 = ""
- Else
- arr = Split(nZs, ",")
- m2 = Split(", Thousand , Million , Billion ", ",")
- For i = 0 To UBound(arr)
- c1 = c1 & IIf(ZH(arr(i)) = "", "", ZH(arr(i)) & m2(UBound(arr) - i))
- Next
- End If
- c2 = IIf(ZH(nXs) = "", "", IIf(c1 <> "", " And ", "") & "Cents " & ZH(nXs))
- albToEn = c1 & c2
- End Function
- Function ZH(n100) As String
- Dim cN$, c1$, c2$
- cN = Format(n100, "000")
- s = Val(Right(cN, 2))
- m0 = Split("One,Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten,Eleven,Twelve," & _
- "Thirteen,Fourteen,Fifteen,Sixteen,Seventeen,Eighteen,Nineteen", ",")
- m1 = Split("Twenty,Thirty,Forty,Fifty,Sixty,Seventy,Eighty,Ninety", ",")
- If s > 0 And s < 20 Then
- c2 = m0(s - 1)
- ElseIf s > 19 And s < 100 Then
- c2 = m1(Left(s, 1) - 2)
- If Right(s, 1) > "0" Then c2 = c2 & " " & m0(Right(s, 1) - 1)
- End If
- If Val(Left(cN, 1)) > 0 Then c1 = m0(Left(cN, 1) - 1) & " Hundred "
- ZH = c1 & c2
- End Function
复制代码 |
评分
-
2
查看全部评分
-
|