lua 创建一百以内的数字汉字

闲来无事写的

function createChineseNumList()
    local list_unit = {"", "十", "百", "千", "万", "十", "百", "千", "亿", "十", "百", "千", "万", "十", "百", "千"}
    local list_num = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"}
    for i=0, 9 do
        for j=0, 9 do
            local num = i*10+j
            local str = ""
            --先处理十位
            if i == 0 then --如果是个位数 跳过
                str = str
            elseif i == 1 then --如果十位是一 十位不加一
                str = list_unit[2]
            else --其他的加
                str = list_num[i+1]..list_unit[2]
            end
            --再处理个位
            if j == 0 then --如果个位是零 不读
                str = str
            else --其他的加
                str = str..list_num[j+1]
            end
            --特殊处理0
            if string.len(str) == 0 then
                str = list_num[1]
            end
            hg.ChineseNumList[num] = str
        end
    end
end

猜你喜欢

转载自blog.csdn.net/qql7267/article/details/80899361
LUA