Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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;
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #double #decimal #places
ADD COMMENT
Topic
Name
3+9 =