红宝石 |数值幅度()函数
大小()是 Ruby 中的一个内置方法,用于返回数字的大小。
Syntax: num.magnitude
Parameters: The function needs the number whose magnitude is to be returned.
Return Value: It returns the magnitude of a number.
示例 1 :
Ruby
# Ruby program for magnitude() method in Numeric
# Initialize a number
num = -19
# Prints magnitude of num
puts num.magnitude()
Ruby
# Ruby program for magnitude() method in Numeric
# Initialize a number
num = 100
# Prints magnitude of num
puts num.magnitude()
输出:
19
示例 2 :
红宝石
# Ruby program for magnitude() method in Numeric
# Initialize a number
num = 100
# Prints magnitude of num
puts num.magnitude()
输出:
100