Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Math (Lua)导入/要求数学模块不';行不通_Math_Lua - Fatal编程技术网

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

这回答了你的问题吗?这回答了你的问题吗?