Ruby Float modulo() 方法与示例
Float modulo()是一个浮点类方法,它返回两个浮点值相除的余数。
Syntax: float.modulo()
Parameter: remainder value from the operation p/q
Return: Modulo i.e. Remainder
Example #1: modulo() 方法的例子
# Ruby program for modulo() method
# Initilizig value
a = 26.00
b = 8.0
# Printing result
puts "numerator : #{a}\n\n"
puts "Division float/float : #{a.modulo(b)}\n\n"
puts "Division float/float : #{b.modulo(a)}\n\n"
输出 :
numerator : 26.0
Division float/float : 2.0
Division float/float : 8.0
示例 #2:
# Ruby code for modulo() method
# Initializing value
a = 7.00.numerator()
# Printing result
puts "numerator : #{a}\n\n"
puts "Division float/int : #{a.modulo(4)}\n\n"
puts "Division float/float : #{a.modulo(4.0)}\n\n"
输出 :
numerator : 7
Division float/int : 3
Division float/float : 3.0