6.11.155 rintf Function

Returns the single precision floating-point argument rounded to an integer value.

Include

<math.h>

Prototype

float rintf(float x);

Argument

x
the value to round

Return Value

Returns the value of x rounded to an integer value using the current rounding direction, raising the inexact floating-point exception should the result not have the same value as the argument. The rounded integer is returned as a single precision floating-point value.

Example

See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

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

int main(void)
{
  float x, y;

  x = 10.103;
  y = rintf(x);
  printf("The nearest integer value to %f is %f\n", x, y);

  x = 10.51;
  y = rintf(x);
  printf("The nearest integer value to %f is %f\n", x, y);
}

Example Output

The nearest integer value to 10.103000 is 10.000000
The nearest integer value to 10.510000 is 11.000000