lua 数字转换 带千位间隔符

作者:雨辰 发布于:2017-8-22 20:02 Tuesday 分类:Lua

--获取数字带千位间隔符
function Fishing_NumberFormat(num, deperator)
    local str1 = ""
    local str = tostring(num)
    local strLen = string.len(str)

    if deperator == nil then
        deperator = ","
    end
    deperator = tostring(deperator)

    for i = 1, strLen do
        str1 = string.char(string.byte(str, strLen + 1 - i)) .. str1
        if math.mod(i, 3) == 0 then
            -- 下一个数 还有
            if strLen - i ~= 0 then
                str1 = deperator .. str1
            end
        end
    end
    return str1
end

标签: lua

发表评论:

雨辰 joyimp|@2011-2017 京ICP备16030765号