how to round a decimal number in c++ 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: round double to n decimal places c++
value = round( value * 100.0 ) / 100.0; // 2 decimal places
value = round( value * 1000.0 ) / 1000.0; // 3 decimal places