methods such as div, modulo, divmod, quo, and remainder. : Math Operators « Language Basics « Ruby






methods such as div, modulo, divmod, quo, and remainder.


puts 24.div 2 # division
puts (25.0).div(2.0) # result is integer
puts 12.modulo 5 # modulo
puts 12.modulo(5.0) # modulo with float
puts 12.divmod 5 # return array with quotient, modulus
puts 12.0.divmod 5.0 # with float
puts 12.quo 5 # return the quotient
puts 12.remainder 5 # return the remainder

 








Related examples in the same category

1.get acquainted with math operations in Ruby
2.Using Math Operators
3.A few of Ruby's assignment operators
4.Some of the operators have assignment shortcuts
5.unary operators, + and -, which indicate negative and positive numbers
6.Division and Truncation
7.be careful when you use the div method
8.Abbreviated Assignment Operators
9.note Ruby does not have ++