Syntax
local whole, fraction = math.modf(value)Examples
Lua integral and fractional parts
Run with standalone Lua 5.4: lua example.lua. These scripts target Lua 5.4 rather than Roblox Luau.
local whole, fraction = math.modf(-3.75)
print(whole)
print(fraction)
print(math.floor(-3.75))- Numeric output: -3, -0.75, then -4. Truncation and rounding downward have different results for negative values.
Best practices
- Choose truncation or floor according to the intended rule. Binary floating-point fractions are not always exact.
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