Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

float
ruby
modulo
communitycreator

What is float.modulo() in Ruby?

okwudili onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

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 the modulo() method. It is the dividend.
  • other: This is the divisor. It is another float value that divides the float_value. When the division is done, the modulo() 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 values
f1 = 3.5555
f2 = 45.00
f3 = -0.999
f4 = 200.12
# invoke the modulo() method
# and print results
puts f1.modulo(2.3)
puts f2.modulo(1.0)
puts f3.modulo(-2.1)
puts f4.modulo(100.12)
Get the modulo of division of float values

Explanation

  • Lines 2-5: Float values f1, f2, f3 and f4 were 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.

RELATED TAGS

float
ruby
modulo
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring