红宝石 |数字 to_c()函数
to_c()是 Ruby 中的一个内置方法,它返回一个带有 num 的复数。
Syntax: num.to_c()
Parameters: The function needs the number which is to be returned as complex.
Return Value: It returns the complex number.
示例 1 :
# Ruby program for to_c()
# method in Numeric
# Initialize a number
num1 = 10
# Prints the to_c
puts num1.to_c()
输出:
10+0i
示例 2 :
# Ruby program for to_c()
# method in Numeric
# Initialize a number
num1 = Complex(19, -7)
# Prints the to_c
puts num1.to_c()
输出:
19-7i