Type Function Library math.* Return value Numbers Revision Release 2024.3703 Keywords modf
Returns two numbers, the integral part of x
and the fractional part of x
.
For the modulus (remainder), use the modulo operator %
instead.
math.modf( x )
Number. A number.
print( math.modf(5) ) ----> 5 0 print( math.modf(5.3) ) ----> 5 0.3 print( math.modf(-5.3) ) ----> -5 -0.3
local myNumber = 4.75 local integralPart, fractionalPart = math.modf( myNumber ) print( "Integral Part:", integralPart ) print( "Fractional Part:", fractionalPart )