Horje
Ruby Float magnitude() method with example

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

Syntax: float.magnitude()

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

Return: absolute value of the passed float value

Example #1:




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

Output :

magnitude value of a : 56.23333333

magnitude value of b : 10000.0

magnitude value of c : 29.1

Example #2:




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

Output :

magnitude value of a : 111.10000000000001

magnitude value of b : 200000.0

magnitude value of c : 116.4



Reffered: https://www.geeksforgeeks.org


Ruby

Related
Ruby Float modulo() method with example Ruby Float modulo() method with example
Ruby Float nan?() method with example Ruby Float nan?() method with example
Ruby Float next_float() method with example Ruby Float next_float() method with example
Ruby Float prev_float() method with example Ruby Float prev_float() method with example
Ruby Float quo() method with example Ruby Float quo() method with example

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
8