--- 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
function Mathf.CutTail(value,multiple,cut)
local n = math.pow(10,multiple)
if not cut then
return math.floor(value * n + 0.5)/n
else
return math.floor(value * n)/n
end
end
string.format("%.1f",0.16) 默认会四舍五入比如:%0.2f 会四舍五入后,保留小数点后2位print(string.format("%.1f",0.16)) ---会输出0.2,而不是0.1Lua保留一位小数--- nNum 源数字--- n 小数位数function Tool. GetPreciseDecimal(nNum, n) if type(nNum) ~= "number" then return nNum; en