Modulo
Published Jul 27, 2021Updated Sep 9, 2021
Contribute to Docs
A Ruby function that returns the modular value, the remainder, when two numbers are divided.
Syntax
x.modulo(y)
- where
x
is the dividend andy
is the divisor. Two values are required.
Example 1
puts 5.modulo(3)# Output: 2
5
is divided by3
and the remainder is2
.
Example 2
puts 10.modulo(3)# Output: 1
10
is divided by3
and the remainder is1
.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Ruby on Codecademy
- Free course
Learn Ruby
Learn to program in Ruby, a flexible and beginner-friendly language used to create sites like Codecademy.Beginner Friendly9 hours - Course
Learn Ruby on Rails
Learn the basics of building applications with this convenient and powerful web development framework.With CertificateIntermediate6 hours