关于钻石太多的显示问题

来源:互联网 发布:影楼相册排版软件 编辑:程序博客网 时间:2024/04/24 04:54

啥也不说了,直接上代码:

 --格式化数字
--超过6位数,截断万位,用万字替代
--超过9位数,截断亿位,用亿字替代
function FormatNumToString(num)
    
    num = num or 0

    local s = num;
    local len = string.len(tostring(num));
    
    if len >= 6 and len < 9 then
        if len <= 8 then
            s = string.format("%.1f", num/10000) .. "万"
        else
            s = string.format("%.0f", num/10000) .. "万"
        end
    elseif len >= 9 then
        if len <= 10 then
            s = string.format("%.1f", num/100000000) .. "亿"
        else
            s = string.format("%.0f", num/100000000) .. "亿"
        end
    end
    return s;
end

function FormatDigitToString(num,limit)
    
    local s = num;
    local len = string.len(tostring(num));
    
    if len >= 5 and len < 9 then
        s = string.format("%."..limit.."f", num/10000) .. "万"
    elseif len >= 9 then
        s = string.format("%."..limit.."f", num/100000000) .. "亿"
    end
    return s;
end

看着办吧!!!!



原创粉丝点击