Skip to content
Related Articles

Related Articles

Improve Article

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




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

Output:  

19

Example 2

Ruby




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

Output:  

100

 

My Personal Notes arrow_drop_up
Recommended Articles
Page :