红宝石 |数值模()函数
modulo()是 Ruby 中的一个内置方法,当两个数字相除时返回模值。它返回 a 模 b 的值。
Syntax: a.modulo(b)
Parameters: The function needs two number whose modulus on division is returned.
Return Value: It returns the modulus when two numbers are divided.
示例 1 :
# Ruby program for % method in Matrix
# Initialize two numbers
a = 19
b = 4
# Prints a % b
puts a.modulo(b)
输出:
3
示例 2 :
# Ruby program for modulo() method in Matrix
# Initialize two numbers
a = 13
b = 2
# Prints a % b
puts a.modulo(b)
输出:
1