Open In App

Ruby | Numeric magnitude() function

Last Updated : 19 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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

 



Next Article

Similar Reads