print(math.floor(12.5928))
以上代码打印出12。如何使它打印出12.5?
print(math.floor(12.5928 * 10) / 10)
function round(number, decimals)
local power = 10^decimals
return math.floor(number * power) / power
end
round(12.5928, 1)
会得到12.5
。print(string.format("%.2f", 129.65686))
保留两位小数: print(math.floor((12.5928) * 100) / 100)