rint()
Anonymous contributor
Anonymous contributor3 total contributions
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 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
:
All contributors
- Anonymous contributorAnonymous contributor3 total contributions
- garanews209 total contributions
- Anonymous contributor
- garanews
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.