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;