|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 mzbao 于 2020-3-2 19:43 编辑
自己写了个。和上面的思路完全不一样。
- Function NumToCN(ByVal ArabicNum) As String
- If Not IsNumeric(ArabicNum) Then
- If Trim(ArabicNum) <> "" Then NumToCN = "N/A" Else NumToCN = ""
- Exit Function
- End If
-
- Dim strInt&, strDec$, i%, strNumCN$, strTempCN$, strMinus$
-
- strNumCN = "〇一二三四五六七八九"
-
- If ArabicNum < 0 Then strMinus = "负"
- If InStr(ArabicNum, ".") Then strDec = Split(ArabicNum, ".")(1)
- ArabicNum = Int(Abs(ArabicNum))
- strTempCN = Format(ArabicNum, "0千0百0十0兆0千0百0十0亿0千0百0十0万0千0百0十0")
- For i = 1 To 3: strTempCN = Replace(strTempCN, 0 & Mid("千百十", i, 1), 0): Next
- For i = 1 To 3: strTempCN = Replace(strTempCN, "0000" & Mid("兆亿万", i, 1), ""): Next
- For i = 1 To 3: strTempCN = Replace(strTempCN, "00", 0): Next
- For i = 1 To 3: strTempCN = Replace(strTempCN, "0" & Mid("兆亿万", i, 1), Mid("兆亿万", i, 1)): Next
- If ArabicNum = 0 Then strTempCN = "〇"
- If Left(strTempCN, 1) = 0 Then strTempCN = Mid(strTempCN, 2)
- If Right(strTempCN, 1) = 0 Then strTempCN = Left(strTempCN, Len(strTempCN) - 1)
- If Len(strDec) Then strTempCN = strTempCN & "点" & strDec
- For i = 0 To 9: strTempCN = Replace(strTempCN, i, Mid(strNumCN, i + 1, 1)): Next
-
- NumToCN = strMinus & strTempCN
- End Function
复制代码 |
评分
-
1
查看全部评分
-
|