zoukankan      html  css  js  c++  java
  • 阿拉伯数字转中文数字

    推荐阅读:

    例如:将102转为一百零二;将08转为八。

    local chnNumChar = {"零","一","二","三","四","五","六","七","八","九"} 
    local chnUnitChar = {"","十","百","千"}
    local chnUnitSection = {"","万","亿","万亿"}
    local function sectionTOChinese(section,chineseNum)
        local setionChinese = ""
        local unitPos = 1
        local zero = true
        while(section>0)
        do
            local v = section%10
            if v == 0 then
                if (not zero) then 
                    zero = true
                    chineseNum = chnNumChar[1] .. chineseNum
                end
            else
                zero = false
                setionChinese = chnNumChar[v+1]
                setionChinese = setionChinese .. chnUnitChar[unitPos] 
                chineseNum = setionChinese .. chineseNum
            end 
            unitPos = unitPos + 1
            section = math.floor(section/10)
        end
          
        return chineseNum 
    end
    
    local function NumberToChinese(num)
        if num == 0 then  
            return "零" 
        end
        local unitPos = 1 --节权位标识  
        local All = ""
        local chineseNum = ""
        local needZero = false --下一小结是否需要补零  
        local strIns = ""
        while(num>0)
        do
            local section = num%10000--取最后面的那一个小节  
            if needZero then --判断上一小节千位是否为零,为零就要加上零  
                All = chnNumChar[1] .. All
            end
            chineseNum = sectionTOChinese(section,chineseNum)
            if section ~= 0 then
                strIns = chnUnitSection[unitPos]
                chineseNum = chineseNum .. strIns
            else 
                strIns = chnUnitSection[1]
                chineseNum = strIns .. chineseNum 
            end
            All = chineseNum .. All 
            chineseNum = "" 
            needZero = (section<1000) and (section>0)  
            num = math.floor(num/10000)
            unitPos = unitPos + 1
        end 
        return All
    end
    
  • 相关阅读:
    Python编程第5讲—if 语句
    GIT 笔记
    jQuery多余文字折叠效果
    静态库与动态库的制作与使用
    Makefile
    C++ 有理数类
    使用mstest.exe 命令行跑test case(不安装Visual Studio 2010)
    Termp Folder and its subfolders
    ToString() 格式化字符串总结
    REST基础
  • 原文地址:https://www.cnblogs.com/shirln/p/12143580.html
Copyright © 2011-2022 走看看