Compartilhar via


round, roundf, roundl

Arredonda um valor de ponto flutuante para o inteiro mais próximo.

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

Parâmetros

  • x
    O valor exponencial de ponto flutuante para arredondar.

Valor de retorno

As funções de round retornam um valor de ponto flutuante que representa o inteiro mais próximo a x. Os valores incompletos são arredondados para cima, independentemente da configuração do modo por arredondamento de ponto flutuante. Não há nenhum retorno de erro.

Entrada

Exceção SEH

Exceção Matherr

± QNAN,IND

nenhum

_DOMAIN

Comentários

Como o C++ permite a sobrecarga, você pode chamar as sobrecargas de round que levam e retornam valores float e long double. Em um programa em C, round sempre obterá e retornará um double.

Requisitos

Rotina

Cabeçalho necessário

round, roundf, roundl

<math.h>

Para obter informações adicionais sobre compatibilidade, consulte Compatibilidade.

Exemplo

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

Equivalência do .NET Framework

System::Math::Round

Consulte também

Referência

Suporte de ponto flutuante

ceil, ceilf, ceill

floor, floorf, floorl

fmod, fmodf

lround, lroundf, lroundl, llround, llroundf, llroundl

rint, rintf, rintl

Outros recursos

lrint, lrintf, lrintl, llrint, llrintf, llrintl

nearbyint, nearbyintf, nearbyintl