Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Ruby Float absolute() method with example

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Float abs() is a float class method which works on float values and converts them to the absolute form.

Syntax: float.abs()

Parameter: float value which is to be converted to absolute value

Return: absolute value of the passed float value

Example #1 :




# Ruby code for abs() method
  
# Initializing value
a = -56.23333333
b = -10000.0
c = -(22 + 7.1)
  
# Printing result
puts "absolute value of a : #{a.abs}\n\n"
puts "absolute value of b : #{b.abs}\n\n"
puts "absolute value of c : #{c.abs}\n\n"

Output :

absolute value of a : 56.23333333

absolute value of b : 10000.0

absolute value of c : 29.1

Example #2 :




# Ruby code for abs() method
  
# Initializing value
a = -100.7 - 10.4
b = -100 * 2000.0
c = -(22 + 7.1) * 4
  
# Printing result
puts "absolute value of a : #{a.abs}\n\n"
puts "absolute value of b : #{b.abs}\n\n
puts "absolute value of c : #{c.abs}\n\n"

Output :

absolute value of a : 111.10000000000001

absolute value of b : 200000.0

absolute value of c : 116.4
My Personal Notes arrow_drop_up
Last Updated : 07 Jan, 2020
Like Article
Save Article
Similar Reads