Horje
Ruby | Numeric to_c() function

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:




# Ruby program for to_c()
# method in Numeric
  
# Initialize a number 
num1 = 10
  
# Prints the to_c
puts num1.to_c()

Output:

10+0i

Example 2:




# Ruby program for to_c()
# method in Numeric
  
# Initialize a number 
num1 = Complex(19, -7)
  
# Prints the to_c
puts num1.to_c()

Output:

19-7i



Reffered: https://www.geeksforgeeks.org


Ruby

Related
Ruby | Rational denominator() function Ruby | Rational denominator() function
Ruby | Rational ceil() function Ruby | Rational ceil() function
Ruby | Numeric round() function Ruby | Numeric round() function
Ruby Basic Syntax Ruby Basic Syntax
Ruby | Numeric finite?() function Ruby | Numeric finite?() function

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
9