S
zum Beispiel so:
//---------------------------------------------------------------------------
// LUT für 10^x (max. x = 9)
//---------------------------------------------------------------------------
static const double Power10_LUT[] = { 1.0, 10.0, 100.0, 1000.0, 10000.0,
100000.0, 1000000.0, 10000000.0, 100000000.0, 1000000000.0 };
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Funktion rundet die angegebene Gleitkommazahl auf die gewünschte
// Anzahl an Nachkommastellen.
//
// Parameter:
// ==========
// double Value : zu rundender Wert
// int Precision : Anzahl der Nachkommastellen
//
// Rückgabe:
// =========
// double : auf Precision gerundeter Wert
//---------------------------------------------------------------------------
double Round(const double Value, const int Precision)
{
if (Precision < 0) return Value;
double Power10;
if (Precision > 9) Power10 = pow(10.0, (double) Precision);
else Power10 = Power10_LUT[Precision];
double TmpValue = Value * Power10;
double FloorValue = floor(TmpValue);
return (FloorValue + 0.5) >= TmpValue ? ( FloorValue / Power10) :
((FloorValue + 1.0) / Power10);
}