Modulo

A Ruby function that returns the modular value, the remainder, when two numbers are divided.

Syntax

x.modulo(y)
  • where x is the dividend and y is the divisor. Two values are required.

Example 1

puts 5.modulo(3)
# Output: 2
  • 5 is divided by 3 and the remainder is 2.

Example 2

puts 10.modulo(3)
# Output: 1
  • 10 is divided by 3 and the remainder is 1.

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn Ruby on Codecademy

Contributors