how to round off float value in c++ to 2 decimal places code example
Example 1: 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
Example 2: round double to 2 decimal places c++
double d = 0.12345;
std::cout.precision(2); // for accuracy to 2 decimal places
std::cout << d << std::endl; // 0.12