Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
nearbyint() function in C++
In this article we will be discussing the working, syntax and examples of nearbyint() function in C++ STL.
What is nearbyint()?
nearbyint() function is an inbuilt function in C++ STL, which is defined in <cmath> header file. nearbyint() function is used to get the round integral value as per the input.
The function rounds off the input to get a nearest integral value, the round method is described by fegetround.
This function accepts the float, double, and long double type values, as arguments.
Syntax
double nearbyint(double num); float nearbyint(float num); long double nearbyint(long double num);
Parameters
The function accepts following parameter(s) −
- num − The value which is to be rounded off.
Return value
This function returns a rounded off value of num.
Example
Input
nearbyint(2.13);
Output
2
Input
nearbyint(3.4);
Output
3
Example
#include <bits/stdc++.h>
using namespace std;
int main(){
float var = 3.4;
cout<<"value of var is: " <<var<< endl;
cout<<"value after round off is: "<<nearbyint(var);
return 0;
}
Output
value of var is: 3.4 value after round off is: 3
Example
#include <bits/stdc++.h>
using namespace std;
int main(){
float var = 7.9;
cout<<"value of var is: " <<var<< endl;
cout<<"value after round off is: "<<nearbyint(var);
return 0;
}
Output
value of var is: 7.9 value after round off is: 8
Advertisements