fmod()

Published Oct 26, 2023
Contribute to Docs

The method fmod() takes two numbers and returns the remainder of the first number divided by the second number.

Syntax

The syntax of fmod() is as follows:

math.fmod(num1, num2)

Where num1 is the value to be divided by num2.

Examples

The following examples illustrate the behavior of fmod():

print(math.fmod(6, 4))
print(math.fmod(4, 6))
print(math.fmod(12, 4))
print(math.fmod(8.04829, 1))
print(math.fmod(4.63, 2.89))
print(math.fmod(0, 9))

This results in the output:

2
4
0
0.04829
1.74
0

All contributors

Looking to contribute?

Learn Lua on Codecademy