Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

ruby
communitycreator

How to find the numerator of a float value in Ruby

okwudili onyejiaku

Overview

We can get the numerator of a float value by using the numerator method.

Syntax

float_value.numerator

Parameters

float_value: This is the float value we want to get the numerator of.

Return value

The value returned is an integer that represents the numerator of the float value, float_value.

Note: The numerator returned is machine dependent.

Code example

# create float values
f1 = 2.0 
f2 = 5 / 2
f3 = 0.666
f4 = 100.77

# get numerator
puts f1.numerator
puts f2.numerator
puts f3.numerator
puts f4.numerator
Get the numerator of a float value in Ruby

Explanation

  • Lines 2-5: We create some float values.
  • Lines 8-11: We invoke the numerator method on the float values we created. We then print the results to the console.

RELATED TAGS

ruby
communitycreator
RELATED COURSES

View all Courses

Keep Exploring