trunc Function

Rounds the argument rounded to an integer value no large than the argument value.

Include

<math.h>

Prototype

double trunc(double x);

Argument

x
the value to round

Return Value

Returns the value of x rounded to the nearest integer value that is no larger in magnitude that the original argument. The rounded integer is returned as a floating-point value.

Example

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

int main(void)
{
  double x, y;

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

  x = 10.9;
  y = trunc(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.900000 is 10.000000