Ruby Integer abs() function with example
Last Updated :
09 Jan, 2020
The abs() function in Ruby returns the absolute value of the integer.
Syntax: (number).abs
Parameter: The function takes the integer whose absolute value is to be returned.
Return Value: The function returns the absolute value of the integer.
Example #1:
num1 = - 21
num2 = 21
num3 = 0
num4 = - 100
puts (num1).abs
puts (num2).abs
puts (num3).abs
puts (num4).abs
|
Output :
21
21
0
100
Example #2:
num1 = 29
num2 = - 7
num3 = 90
num4 = - 10
puts (num1).abs
puts (num2).abs
puts (num3).abs
puts (num4).abs
|
Output:
29
7
90
10
Share your thoughts in the comments
Please Login to comment...