|
VFP 愛用者社區 本討論區為 Visual Foxpro 愛用者經驗交流的地方, 請多多利用"搜尋"的功能, 先查看看有無前例可循, 如果還有不懂的再發問. 部份主題有附加檔案, 須先註冊成為社區居民才可以下載.
|
上一篇主題 :: 下一篇主題 |
發表人 |
內容 |
Ruey
註冊時間: 2003-03-12 文章: 1698 來自: tunglo
第 1 樓
|
發表於: 星期日 四月 13, 2003 3:24 pm 文章主題: 中文大寫金額轉成阿拉伯數字 |
|
|
vb範例
Function ChineseFormat(n As Variant)
Dim s As String, sFormat As String
Dim i As Integer, c As String
Const sString = "分角元拾佰仟萬拾佰仟億拾佰仟萬"
Const sNumber = "零壹貳三肆伍陸柒捌玖"
s = Format(Int(n * 100))
sFormat = ""
For i = Len(s) To 1 Step -1
c = Mid(s, i, 1)
sFormat = Mid(sNumber, Val(c) _
+ 1, 1) + Mid(sString, Len(s) - i + 1, 1) _
+ sFormat
Next
ChineseFormat = sFormat
End Function
對於數位中出現0的情況,如
Print ChineseFormat(2008.04)
這個函數的輸出結果是“貳仟零佰零拾捌元零角肆分”,如果希望結果是“貳仟零捌元零角肆分”。可以修改函數為:
Function ChineseFormat(n As Variant)
Dim s As String, sFormat As String
Dim i As Integer, c As String
Const sString = "分角元拾佰仟萬拾佰仟億拾佰仟萬"
Const sNumber = "零壹貳三肆伍陸柒捌玖"
s = Format(Int(n * 100))
sFormat = ""
For i = Len(s) To 1 Step -1
c = Mid(s, i, 1)
If c = "0" Then
Select Case Len(s) - i
Case Is <= 1 ' 0在元之後
sFormat = "零" + Mid(sString, Len(s) - i + 1, 1) _
+ sFormat
Case 2 ' 元
sFormat = "元" + sFormat
Case Else
If Mid(s, i + 1, 1) <> "0" Then sFormat = "零" + sFormat
End Select
Else
sFormat = Mid(sNumber, Val(c) _
+ 1, 1) + Mid(sString, Len(s) - i + 1, 1) _
+ sFormat
End If
Next
ChineseFormat = sFormat
End Function |
|
回頂端 |
|
|
|
|
您 無法 在這個版面發表文章 您 無法 在這個版面回覆文章 您 無法 在這個版面編輯文章 您 無法 在這個版面刪除文章 您 無法 在這個版面進行投票 您 無法 在這個版面附加檔案 您 無法 在這個版面下載檔案
|
|