util.math.type
Shared
Returns the numeric subtype of a value as a string, or false if the value is not a number
Syntax
local result = util.math.type(
value
)Parameters
| Type | Name | Description |
|---|---|---|
any | value | Value to check the numeric subtype of |
Returns
| Type | Name | Description |
|---|---|---|
string | bool | result | Numeric subtype of value: • "integer" - when value is an integer • "float" - when value is a float • false - when value is not a number |
Examples
local result = util.math.type(1)
core.engine.print("info", result) -- 'integer'local result = util.math.type(1.0)
core.engine.print("info", result) -- 'float'local result = util.math.type("hello")
core.engine.print("info", result) -- falselocal result = util.math.type(10 // 3)
core.engine.print("info", result) -- 'integer'local result = util.math.type(10/3)
core.engine.print("info", result) -- 'float'core.engine.print("info", util.math.type(1)) -- 'integer'
core.engine.print("info", util.math.type(1.0)) -- 'float'local values = {1, 2.5, 3, 4.0, "hi"}
for _, v in ipairs(values) do
local subtype = util.math.type(v)
if subtype == "integer" then
core.engine.print("info", v, "is an integer")
elseif subtype == "float" then
core.engine.print("info", v, "is a float")
else
core.engine.print("info", v, "is not a number")
end
end