Horje
Ruby | Float numerator() method

Float numerator() is a float class method which return a float value as the numerator value for p/q form.

Syntax:float.numerator()

Parameter: float value (p) for the p/q form. [Always positive]

Return: A machine-dependent result.

Example #1:




# Ruby program for numerator() method
  
a = 2.0.numerator()
  
# Returning machine dependent result
puts "numerator : #{a}\n\n"
  
# Using as a numerator
puts "Division int/float : #{a.fdiv(4)}\n\n"
puts "Division float/float : #{a.fdiv(4.0)}\n\n"

Output :

numerator : 2

Division int/float : 0.5

Division float/float : 0.5

Example #2:




# Ruby program for numerator() method
  
# Initializing value
a = 0.numerator()
  
# returning machine dependent result
puts "numerator : #{a}\n\n"
puts "Division int/float : #{a.fdiv(4)}\n\n"
puts "Division float/float : #{a.fdiv(4.0)}\n\n"

Output :

numerator : 0

Division int/float : 0.0

Division float/float : 0.0




Reffered: https://www.geeksforgeeks.org


Ruby

Related
Ruby Float divmod() method with example Ruby Float divmod() method with example
Ruby Float negative() method with example Ruby Float negative() method with example
Ruby Float fdiv() method with example Ruby Float fdiv() method with example
Ruby Float magnitude() method with example Ruby Float magnitude() method with example
Ruby Float modulo() method with example Ruby Float modulo() method with example

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