C Standard Library

C <math.h> - round() Function



The C <math.h> round() function returns an integral value that is nearest to the argument value, regardless of the current rounding mode. In halfway cases, the argument is rounded away from zero.

Syntax

double round  (double x);
float roundf (float x);
long double roundl (long double x);                    

Parameters

x Specify a value to round.

Return Value

Returns an integral value by rounding up the x to the nearest integral value.

Example:

In the example below, round() function is used to round the given number.

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

int main (){

  printf("round(10.2): %.1f\n", round(10.2));
  printf("round(10.8): %.1f\n", round(10.8));
  printf("round(-5.2): %.1f\n", round(-5.2));
  printf("round(-5.8): %.1f\n", round(-5.8));
  return 0;
}

The output of the above code will be:

round(10.2): 10.0
round(10.8): 11.0
round(-5.2): -5.0
round(-5.8): -6.0

❮ C <math.h> Library

5