📅  最后修改于: 2023-12-03 15:27:31.546000             🧑  作者: Mango
In programming, it is often necessary to round numbers down to the nearest integer. The floor() function in Ruby helps us achieve this by returning the largest integer less than or equal to a given number.
The syntax for using the floor() function in Ruby is as follows:
number.floor
Let's say we have a number, 4.9 and we wish to round it down to the nearest integer:
number = 4.9
result = number.floor
puts result
The output of this program will be:
4
# Red Ruby | The floor() Function
## Introduction
In programming, it is often necessary to round numbers down to the nearest integer. The floor() function in Ruby helps us achieve this by returning the largest integer less than or equal to a given number.
## Syntax
The syntax for using the floor() function in Ruby is as follows:
```ruby
number.floor
```
## Example
Let's say we have a number, 4.9 and we wish to round it down to the nearest integer:
```ruby
number = 4.9
result = number.floor
puts result
```
The output of this program will be:
```
4
```