rint()

Anonymous contributor's avatar
Anonymous contributor
Anonymous contributor's avatar
Anonymous contributor
Published Oct 25, 2022Updated Nov 17, 2022
Contribute to Docs

The rint() function rounds the argument to an integral value using the current rounding direction.

Syntax

rint(x)

The x parameter must be a double, float, or long double. The return value will be the same data type.

Note: The rounding direction is specified by the fegetround() function, with the default direction set as to the nearest. The rounding direction can be set to other values using fesetround() function.

Example

The following example uses the rint() function to find the value of x after rounding off:

#include <iostream>
#include <cmath>
int main() {
double x = 11.87;
double result;
result = rint(x);
std::cout << "Rounding to-nearest integer of (" << x << ") = " << result << "/n";
}

This produces the following output:

Rounding to-nearest integer (11.87) = 12

Codebyte Example

The following example is runnable and returns the value nearest to x:

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn C++ on Codecademy