Horje
round double to n decimal places c++ Code Example
round double to n decimal places c++
float roundoff(float value, unsigned char prec)
{
  float pow_10 = pow(10.0f, (float)prec);
  return round(value * pow_10) / pow_10;
}

auto rounded = roundoff(100.123456, 3);
// rounded = 100.123;
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




Cpp

Related
how to dynamically allocate an array c++ Code Example how to dynamically allocate an array c++ Code Example
how to round a double to 2 decimal places in c++ Code Example how to round a double to 2 decimal places in c++ Code Example
how to initialize array with new in c++ Code Example how to initialize array with new in c++ Code Example
C++ std::string find and replace Code Example C++ std::string find and replace Code Example
find kth max and min element in an array Code Example find kth max and min element in an array Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8