trunc - C math.h

C examples for math.h:trunc

Type

function

From

<cmath>
<ctgmath>
<math.h>

Description

Rounds x toward zero, returning the nearest integral value that is not larger in magnitude than x.

Prototype

long double truncl (long double x);
long double trunc (long double x);
      float truncf (float x);
     double trunc (double x);
      float trunc (float x);
     double trunc (T x);           

Parameters

Parameter Description
x Value to truncate.

Return Value

The nearest integral value that is not larger in magnitude than x as a floating-point value.

Demo Code


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

int main ()//from  w  w w. ja v a2 s .  c  om
{

  printf ("%f", trunc( 2.3));
  printf ("%f", trunc( 2.8));
  printf ("%f", trunc( 2.9));
  printf ("%f", trunc( -2.3));
  printf ("%f", trunc( -2.9));

  return 0;
}

Related Tutorials