Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共3 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:帮忙写一个大写金额转换成小写金额的函数

1楼
keli0917 发表于:2025/1/28 22:21:00
帮助里只有小写转换成大写的函数CUMoney,想要一个大写转换成小写金额的

2楼
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编辑过]
3楼
keli0917 发表于:2025/1/29 19:21:00
已成
[此贴子已经被作者于2025/1/29 22:20:31编辑过]
共3 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .03906 s, 2 queries.