Ruby | Numeric floor() function

The floor() is an inbuilt method in Ruby returns a number less than or equal to the given number with a precision of the given number of digits after the decimal point. In case the number of digits is not given, the default value is taken to be zero.

Syntax: num.floor(ndigits)

Parameters: The function needs a number and ndigits which specifies the number of digits to be round off. If ndigits is not given then, default value is taken to be zero.

Return Value: It returns returns a boolean value.

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for floor()
# method in Numeric
  
# Initialize a number 
num1 = -16.7834
num2 = -16.78324
num3 = 16.873
  
# Prints floor
puts num1.floor(1)
puts num2.floor()
puts num3.floor()

chevron_right


Output:

-16.8
-17
16

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for floor()
# method in Numeric
  
# Initialize a number 
num1 = 12.32
num2 = -1321.998321
num3 = -12.2321
  
# Prints floor
puts num1.floor(1)
puts num2.floor(2)
puts num3.floor(3)

chevron_right


Output:

12.3
-1322.0
-12.233
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.