Related Articles

Related Articles

Ruby | Numeric magnitude() function
  • Last Updated : 19 Jan, 2021

The magnitude() is an inbuilt method in Ruby returns the magnitude of a number. 

Syntax: num.magnitude

Parameters: The function needs the number whose magnitude is to be returned. 

Return Value: It returns the magnitude of a number.

Example 1:  



Ruby

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for magnitude() method in Numeric
 
# Initialize a number
num = -19
 
# Prints magnitude of num
puts  num.magnitude()

chevron_right


Output:  

19

Example 2

Ruby

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for magnitude() method in Numeric
 
# Initialize a number
num = 100
 
# Prints magnitude of num
puts  num.magnitude()

chevron_right


Output:  

100

 

My Personal Notes arrow_drop_up
Recommended Articles
Page :