Freigeben über


round, roundf, roundl

Rundet einen Gleitkommawert auf die nächste Ganzzahl.

double round( 
   double x 
);
float round(
   float x
);  // C++ only
long double round(
   long double x
);  // C++ only
float roundf(
   float x
);
long double roundl(
   long double x
);

Parameter

  • x
    Der zu rundende Gleitkommawert.

Rückgabewert

Die round-Funktionen geben einen Gleitkommawert zurück, der die nächste ganze Zahl zu x darstellt. Halbe Werte werden kaufmännisch gerundet, unabhängig von der Einstellung des Gleitkomma-Rundungsmodus. Es gibt keine Fehlerrückgabe.

Eingabe

SEH-Ausnahme

Matherr-Ausnahme

± QNAN,IND

Keine

_DOMAIN

Hinweise

Da C++ das Überladen zulässt, können Sie Überladungen von round aufrufen, die float- und long double-Werte verwenden und zurückgeben. In einem C-Programm verwendet round immer double und gibt diesen Wert zurück.

Anforderungen

Routine

Erforderlicher Header

round, roundf, roundl

<math.h>

Zusätzliche Informationen zur Kompatibilität finden Sie unter Kompatibilität.

Beispiel

// crt_round.c
// Build with: cl /W3 /Tc crt_round.c
// This example displays the rounded results of
// the floating-point values 2.499999, -2.499999, 
// 2.8, -2.8, 2.5 and -2.5.

#include <math.h>
#include <stdio.h>

int main( void )
{
   double x = 2.499999;
   float y = 2.8f;
   long double z = 2.5;

   printf("round(%f) is %.0f\n", x, round(x));
   printf("round(%f) is %.0f\n", -x, round(-x));
   printf("roundf(%f) is %.0f\n", y, roundf(y));
   printf("roundf(%f) is %.0f\n", -y, roundf(-y));
   printf("roundl(%Lf) is %.0Lf\n", z, roundl(z));
   printf("roundl(%Lf) is %.0Lf\n", -z, roundl(-z));
}
  

.NET Framework-Entsprechung

System::Math::Round

Siehe auch

Referenz

Gleitkommaunterstützung

ceil, ceilf, ceill

floor, floorf, floorl

fmod, fmodf

lround, lroundf, lroundl, llround, llroundf, llroundl

rint, rintf, rintl

Weitere Ressourcen

lrint, lrintf, lrintl, llrint, llrintf, llrintl

nearbyint, nearbyintf, nearbyintl