round(x * 100) / 100.0
If you must keep things floats:
roundf(x * 100) / 100.0
Flexible version using standard library functions:
double GetFloatPrecision(double value, double precision)
{
return (floor((value * pow(10, precision) + 0.5)) / pow(10, precision));
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…