Ruby Integer floor() function with example

The ceil function in Ruby returns the smallest number smaller than or equal to int with a precision of ndigits decimal digits. The default is considered to be 0. When the precision given is negative, the returned value is an integer with at least ndigits.abs trailing zeros. It returns self when ndigits positive.

Syntax: (number).floor(ndigits)

Parameter: The function takes the integer whose floor value is to be returned and a single parameter ndigits which specifies the precision to be returned.

Return Value: The function returns the smallest integer number smaller than or equal to it.

Example #1:



filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program of Integer floor() function
  
# Initializing the numbers 
num1 = 10
num2 = 17
num3 = 17.5
num4 = 21.5
   
# Prints the floor value
puts num1.floor
puts num2.floor(2)
puts num3.floor(-1)
puts num4.floor(0)

chevron_right


Output:

10
17.0
10
21

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program of Integer floor() function
  
# Initializing the numbers 
num1 = 13
num2 = -90
num3 = 90
num4 = 81.7
   
# Prints the floor value
puts num1.floor
puts num2.floor(2)
puts num3.floor(-1)
puts num4.floor(0)

chevron_right


Output:

13
-90
90
81
My Personal Notes arrow_drop_up

The function of education is to teach one to think intensively and to think critically

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.