# Calculate the Floor and Ceiling values in R Programming – floor() and ceiling() Function

`floor()` function in R Language returns the largest integer that is smaller than or equal to value passed to it as argument(i.e : rounds downs to the nearest integer).

Syntax: floor(x)

Parameter:
x: Value to be rounded off

Example 1:

 `# R program to calculate floor value  ` `   `  `# Using floor() method  ` `answer1 <``-` `floor(``1.2``)  ` `answer2 <``-` `floor(``1.5``)  ` `answer3 <``-` `floor(``2.6``)  ` `answer4 <``-` `floor(``-``2.6``)  ` `   `  `print``(answer1)  ` `print``(answer2)  ` `print``(answer3)  ` `print``(answer4)  `

Output:

```1
1
2
-3
```

#### ceiling() Function

`ceiling()` function in R Language returns the smallest integer that is greater than or equal to the value passed to it as argument(i.e : rounds up to the nearest integer).

Syntax: ceiling(x)

Parameter:
x: Value to be rounded off

Example 1:

 `# R program to calculate ceiling value  ` `   `  `# Using ceiling() method  ` `answer1 <``-` `ceiling(``1.2``)  ` `answer2 <``-` `ceiling(``1.5``)  ` `answer3 <``-` `ceiling(``2.6``)  ` `answer4 <``-` `ceiling(``-``2.6``)  ` `   `  `print``(answer1)  ` `print``(answer2)  ` `print``(answer3)  ` `print``(answer4)  `

Output:

```2
2
3
-2
```

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Previous
Next