Skip to content
Related Articles

Related Articles

Ruby | Numeric imag() function
  • Last Updated : 06 Jan, 2020

The imag() is an inbuilt method in Ruby returns the imag part of the given number.

Syntax: num.imag()

Parameters: The function needs a number whose imag part is to be returned.

Return Value: It returns the imag part.

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for imag()
# method in Numeric
  
# Initialize a number 
num1 = Complex(10, 9)
  
# Prints Imaginary number
puts num1.imag()

chevron_right


Output:

9

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for imag()
# method in Numeric
  
# Initialize a number 
num1 = Complex(10, 0)
  
# Prints Imaginary number
puts num1.imag()

chevron_right


Output:

0
My Personal Notes arrow_drop_up
Recommended Articles
Page :