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 = 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" — value is an integer • "float" — value is a float • false — value is not a number |
Examples
local result = math.type(1)
engine.print("info", result) -- 'integer'local result = math.type(1.0)
engine.print("info", result) -- 'float'local result = math.type("hello")
engine.print("info", result) -- falselocal result = math.type(10 // 3)
engine.print("info", result) -- 'integer'local result = math.type(10 / 3)
engine.print("info", result) -- 'float'engine.print("info", math.type(1)) -- 'integer'
engine.print("info", math.type(1.0)) -- 'float'local values = {1, 2.5, 3, 4.0, "hi"}
for _, v in ipairs(values) do
local subtype = math.type(v)
if subtype == "integer" then
engine.print("info", v, "is an integer")
elseif subtype == "float" then
engine.print("info", v, "is a float")
else
engine.print("info", v, "is not a number")
end
end