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