保留小数点后几位

nNum 当前数字

n 保留小数点位数

function 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

猜你喜欢

转载自www.cnblogs.com/AEBOKE/p/12719719.html