rint()
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
:
Contribute to Docs
- 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.
Learn C++ on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn C++
Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.Beginner Friendly11 hours