Ruby 数值 to_c()函数 to_c() 是Ruby中的一个内置方法,用于返回一个带有num的复数。 语法 :num.to_c() 参数 : 该函数需要返回一个复数的数字。 返回值 : 它返回复数。 例子 1 : # Ruby program for to_c() # method in Numeric # Initialize a number num1 = 10 # Prints the to_c puts num1.to_c()RubyCopy 输出: 10+0iRubyCopy 例2 : # Ruby program for to_c() # method in Numeric # Initialize a number num1 = Complex(19, -7) # Prints the to_c puts num1.to_c()RubyCopy 输出: 19-7iRubyCopy