Condividi tramite


round, roundf, roundl

Arrotonda un valore in virgola mobile all'integer più vicino.

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
);

Parametri

  • x
    Il valore a virgola mobile da arrotondare.

Valore restituito

Le funzioni round restituiscono un valore a virgola mobile che rappresenta il valore integer più vicino a x. I valori a metà vengono arrotondati per eccesso, indipendentemente dall'impostazione della modalità di arrotondamento della virgola mobile. Nessun ritorno di errore.

Input

Eccezione SEH

Eccezione Matherr

± QNAN,IND

nessuno

_DOMAIN

Note

Poiché C++ consente l'overload, è possibile chiamare gli overload di round che accettano e restituiscono float e i valori long double. In un programma C, round accetta e restituisce sempre un double.

Requisiti

Routine

Intestazione obbligatoria

round, roundf, roundl

<math.h>

Per ulteriori informazioni sulla compatibilità, vedere Compatibilità.

Esempio

// 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));
}
  

Equivalente .NET Framework

System::Math::Round

Vedere anche

Riferimenti

Supporto a virgola mobile

ceil, ceilf, ceill

floor, floorf, floorl

fmod, fmodf

lround, lroundf, lroundl, llround, llroundf, llroundl

rint, rintf, rintl

Altre risorse

lrint, lrintf, lrintl, llrint, llrintf, llrintl

nearbyint, nearbyintf, nearbyintl