Expand Minimize

rint, rintf, rintl

Visual Studio 2013

Rounds a floating-point value to the nearest integer in floating-point format.

double rint( double x );
float rint( float x );  // C++ only
long double rint( long double x );  // C++ only
float rintf( float x ); 
long double rintl( long double x ); 


The floating-point value to round.

The rint functions return a floating-point value that represents the nearest integer to x. Halfway values are rounded according to the current setting of the floating-point rounding mode, the same as the nearbyint functions. Unlike the nearbyint functions, the rint functions may raise the FE_INEXACT floating-point exception if the result differs in value from the argument. There is no error return.


SEH Exception

_matherr Exception

± ∞, QNAN, IND



Because C++ allows overloading, you can call overloads of rint that take and return float and long double values. In a C program, rint always takes and returns a double.


C header

C++ header

rint, rintf, rintl



For additional compatibility information, see Compatibility.

// crt_rint.c
// Build with: cl /W3 /Tc crt_rint.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("rint(%f) is %.0f\n", x, rint (x));
   printf("rint(%f) is %.0f\n", -x, rint (-x));
   printf("rintf(%f) is %.0f\n", y, rintf(y));
   printf("rintf(%f) is %.0f\n", -y, rintf(-y));
   printf("rintl(%Lf) is %.0Lf\n", z, rintl(z));
   printf("rintl(%Lf) is %.0Lf\n", -z, rintl(-z));
rint(2.499999) is 2
rint(-2.499999) is -2
rintf(2.800000) is 3
rintf(-2.800000) is -3
rintl(2.500000) is 3
rintl(-2.500000) is -3
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft