以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  帮忙写一个大写金额转换成小写金额的函数  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=194889)

--  作者:keli0917
--  发布时间:2025/1/28 22:21:00
--  帮忙写一个大写金额转换成小写金额的函数
帮助里只有小写转换成大写的函数CUMoney,想要一个大写转换成小写金额的


--  作者:keli0917
--  发布时间:2025/1/29 19:20:00
--  
Dim ChineseAmount As String =args(0)
Dim numMap() As String = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"} \'数字映射表
Dim unitMap() As String = {"分", "角", "元", "拾", "佰", "仟", "万", "亿"} \'单位映射表
Dim unitValueMap() As Double = {0.01, 0.1, 1, 10, 100, 1000, 10000, 100000000} \'单位值映射表 
Dim sectionResult As Double
Dim result As Double

Dim currentNum As Double = 0
Dim currentUnit As Double = 0
Dim lenStr As Integer
ChineseAmount = ChineseAmount.Replace("圆","元")
lenStr = ChineseAmount.length
sectionResult = 0
result = 0

For i As Integer = 1 To lenStr
    Dim currentChar As String
    currentChar = ChineseAmount.Chars(i-1)
    
    \' 处理"整"字
    If currentChar = "整" Then
        Exit For
    End If
    
    \' 检查是否为数字 
    Dim isNumber As Boolean = False 
    For numIndex As Integer  = 0 To numMap.length -1
        If currentChar = numMap(numIndex) Then
            isNumber = True 
            currentNum = numIndex
            Exit For
        End If
    Next
   \' Output.Show("i:="&i)
   \' Output.Show("当前字符"&currentChar)
   \' Output.Show("currentNum "&currentNum)
   \' Output.Show("numIndex"& numIndex)

    If isNumber  Then \'如果是数字 
        \' 是数字,继续处理下一个字符
        Continue For
    End If
    
    \' 检查是否为单位
    Dim unitIndex As Integer
    unitIndex = -1
    For unitIndex  = 0 To unitMap.length -1
        If currentChar = unitMap(unitIndex) Then
            currentUnit = unitValueMap(unitIndex)
            If unitIndex = 6 Or unitIndex = 7 Then \' 万或亿
                sectionResult = (sectionResult + currentNum) * currentUnit
                result = result + sectionResult
                sectionResult = 0
            Else 
                sectionResult = sectionResult + currentNum * currentUnit                
            End If
            currentNum = 0
            Exit For
        End If
    Next
Next

result = result + sectionResult

Return result
[此贴子已经被作者于2025/1/29 22:20:57编辑过]

--  作者:keli0917
--  发布时间:2025/1/29 19:21:00
--  
已成
[此贴子已经被作者于2025/1/29 22:20:31编辑过]