Lua fmod()

noahpgordon's avatar
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.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn the basics of Lua, a general-purpose programming language used for building games, web apps, and developer tools.
    • Beginner Friendly.
      4 hours

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

Contribute to Docs

Learn Lua on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn the basics of Lua, a general-purpose programming language used for building games, web apps, and developer tools.
    • Beginner Friendly.
      4 hours