The nearbyint() function is defined in cmath header file. This function round off the given value to a nearby integral value by using the current rounding method. The current rounding method is described by fegetround.
float nearbyint(float x); or, double nearbyint(double x); or, long double nearbyint(long double x);
Parameters: This function accepts single parameter x which contains floating point value.
Return Value: It returns the rounded value of x to a nearby integral value by using the rounding method.
Below programs illustrate the nearbyint() function in C++:
Value of x = 2.7 Round off value of x = 3
Value of x = 3.2 Round off value of x = 3
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Difference between user defined function and library function in C/C++
- How to call some function before main() function in C++?
- Function Overloading vs Function Overriding in C++
- How to call function within function in C or C++
- What happens when a virtual function is called inside a non-virtual function in C++
- Difference between Virtual function and Pure virtual function in C++
- fma() function in C++
- log() function in C++
- exp() function C++
- div() function in C++
- iswxdigit() function in C/C++
- towlower() function in C/C++
- array at() function in C++ STL
- array get() function in C++ STL
- iswspace() function in C/C++
- strtoimax() function in C++
- wctype() function in C/C++
- c32rtomb() function in C/C++
- c16rtomb() function in C/C++
- strtoumax() function in C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.