Answers for "round number 2 decimal places cpp"

C++
3

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;
Posted by: Guest on September-16-2020
0

round double to 2 decimal places c++

double d; 
	std::cout.precision(3); // for accurancy to 3 decimal places
	std::cout << d << std::endl;
Posted by: Guest on October-23-2021

Code answers related to "round number 2 decimal places cpp"

Browse Popular Code Answers by Language