What is float.modulo() in Ruby?
Overview
The modulo() method in Ruby is used to return the modulo after dividing a float value by another.
Note: The modulo is the remainder after dividing one number by another number.
Syntax
float_value.modulo(other)
Parameters
float_value: This float value invokes themodulo()method. It is the dividend.other: This is the divisor. It is another float value that divides thefloat_value. When the division is done, themodulo()method then returns the modulo of the division.
Return value
The value returned is the modulo after the division of float_value by other.
Code example
# create some float valuesf1 = 3.5555f2 = 45.00f3 = -0.999f4 = 200.12# invoke the modulo() method# and print resultsputs f1.modulo(2.3)puts f2.modulo(1.0)puts f3.modulo(-2.1)puts f4.modulo(100.12)
Explanation
- Lines 2-5: Float values
f1,f2,f3andf4were created. - Lines 9-12: The
modulo()method was invoked on the float values we created, which took some other float values, which are the divisors. Then the results were printed to the console.