Lua保留指定小数位数

时间:2018-05-11 22:30:09   收藏:0   阅读:1011

默认会四舍五入

Lua保留一位小数

--- nNum 源数字
--- n 小数位数
function Tool. GetPreciseDecimal(nNum, n)
    if type(nNum) ~= "number" then
        return nNum;
    end
    n = n or 0;
    n = math.floor(n)
    if n < 0 then
        n = 0;
    end
    local nDecimal = 10 ^ n
    local nTemp = math.floor(nNum * nDecimal);
    local nRet = nTemp / nDecimal;
    return nRet;
end

参考:https://www.cnblogs.com/pk-run/p/4444582.html

原文:https://www.cnblogs.com/zhaoqingqing/p/9026523.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!