1float roundoff(float value, unsigned char prec)
2{
3 float pow_10 = pow(10.0f, (float)prec);
4 return round(value * pow_10) / pow_10;
5}
6
7auto rounded = roundoff(100.123456, 3);
8// rounded = 100.123;
1value = round( value * 100.0 ) / 100.0; // 2 decimal places
2value = round( value * 1000.0 ) / 1000.0; // 3 decimal places