我们在写程序的时候,对一些数字的精准度要求要高的,
比如要保留后几位小数但不四舍五入,这是说到的是lua。
--获取准确小数
-- num 源数字
--n 位数
function GetPreciseDecimal(num, n)
if type(num) ~= "number" then
return num
end
n = n or 0
n = math.floor(n)
if n < 0 then n = 0 end
local decimal = 10 ^ n
local temp = math.floor(num * decimal)
return temp / decimal
end