rint()
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 usingfesetround()
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
: