Ruby | Numeric to_c() function
Last Updated :
19 Mar, 2024
The to_c() is an inbuilt method in Ruby returns a complex number with the 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.
Example 1:
num1 = 10
puts num1.to_c()
|
Output:
10+0i
Example 2:
num1 = Complex( 19 , - 7 )
puts num1.to_c()
|
Output:
19-7i
Share your thoughts in the comments
Please Login to comment...