math.modf
Shared
Returns the integer and fractional parts of a number
Syntax
local integer, fraction = math.modf(
value
)Parameters
| Type | Name | Description |
|---|---|---|
number | value | Number to split into integer and fractional parts |
Returns
| Type | Name | Description |
|---|---|---|
int | integer | Integer part of value |
number | fraction | Fractional part of value (same sign as value) |
Examples
local integer, fraction = math.modf(4.75)
engine.print("info", integer, fraction) -- 4 0.75local integer, fraction = math.modf(-3.25)
engine.print("info", integer, fraction) -- -3 -0.25local integer, fraction = math.modf(10.0)
engine.print("info", integer, fraction) -- 10 0.0local integer = math.modf(9.99)
engine.print("info", integer) -- 9local _, fraction = math.modf(9.99)
engine.print("info", fraction) -- 0.99local elapsed = 3.456
local secs, ms = math.modf(elapsed)
engine.print("info", secs, math.floor(ms * 1000)) -- 3 456local n = 5.0
local _, fraction = math.modf(n)
if fraction == 0 then
engine.print("info", "Whole number")
end