c++ round to nearest integer code example

Example 1: c++ round to int

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int x = 15;
    double result;
    result = round(x);
    cout << "round(" << x << ") = " << result << endl;

    return 0;
}

Example 2: nearest integer rounding in c++

cout << "Nearest value of x :" << round(x) << "\n";

Example 3: rounding off to nearest integer in c++

double round(double x);
float round(float x);
long double round(long double x);
double round(T x); // For integral type

Tags:

Cpp Example