红宝石 |数字 imaginary()函数
imaginary()是 Ruby 中的一个内置方法,返回给定数字的虚部。
Syntax: num.imaginary()
Parameters: The function needs a number whose imaginary part is to be returned.
Return Value: It returns the imaginary part.
示例 1 :
# Ruby program for imaginary()
# method in Numeric
# Initialize a number
num1 = Complex(10, 9)
# Prints Imaginary number
puts num1.imaginary()
输出:
9
示例 2 :
# Ruby program for imaginary()
# method in Numeric
# Initialize a number
num1 = Complex(10, 0)
# Prints Imaginary number
puts num1.imaginary()
输出:
0