Math (Lua)导入/要求数学模块不';行不通
我这里有一些代码:Math (Lua)导入/要求数学模块不';行不通,math,lua,Math,Lua,我这里有一些代码: require "math" local dozenDonuts local oneDonut local function roundToFirstDecimal(t) return math.round(t*10)*0.1 end 当我运行上面的代码时,我得到以下错误: lua: f:\my codes\donut.lua:6: attempt to call field 'round' (a nil value) stack traceback: f
require "math"
local dozenDonuts
local oneDonut
local function roundToFirstDecimal(t)
return math.round(t*10)*0.1
end
当我运行上面的代码时,我得到以下错误:
lua: f:\my codes\donut.lua:6: attempt to call field 'round' (a nil value)
stack traceback:
f:\my codes\donut.lua:6: in function 'roundToFirstDecimal'
f:\my codes\donut.lua:17: in main chunk
[C]: ?
round
不是数学的属性吗?如何将整数舍入到第一个小数点?math。round
不是标准Lua数学库的一部分。但写起来很简单:
function math.round(x)
return math.floor(x+0.5)
end
math.round
不是标准Lua数学库的一部分。但写起来很简单:
function math.round(x)
return math.floor(x+0.5)
end
这回答了你的问题吗?这回答了你的问题吗?