Codectionary / Developer documentation / Lua

Lua integer subtypes and conversion

Lua 5.3+ distinguishes integer and floating-point numeric subtypes. math.tointeger converts only exactly representable integer values. Luau instead uses one double-precision number type.

Syntax

math.type(value); math.tointeger(value)

Examples

Lua integer subtypes and conversion

Run with standalone Lua 5.4: lua example.lua. These scripts target Lua 5.4 rather than Roblox Luau.

print(math.type(7))
print(math.type(7.0))
print(math.tointeger(7.0))
print(math.tointeger(7.5) == nil)
  1. Output: integer, float, 7, true. An integral float converts exactly; a fractional value cannot.

Best practices

  • Use math.tointeger when conversion must be exact. Do not assume Luau implements Lua integer-subtype APIs.

Runtime & versions

Lua interpreter or a host application. Feature availability depends on the language and runtime version used by your project; consult the official reference below.

Lua reference manuals

Specifications & further reading