红宝石 |数值百分比法
%是 Ruby 中的一个内置方法,当两个数字相除时返回模值。它返回 a % b 的值。
Syntax: a % 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
# Ruby program for % method in Numeric
# Initialize two numbers
a = 19
b = 4
# Prints a%b
puts a % b
Ruby
# Ruby program for % method in Numeric
# Initialize two numbers
a = 13
b = 2
# Prints a%b
puts a % b
输出:
3
示例 2 :
红宝石
# Ruby program for % method in Numeric
# Initialize two numbers
a = 13
b = 2
# Prints a%b
puts a % b
输出:
1