C examples for math.h:trunc
function
<cmath> <ctgmath> <math.h>
Rounds x toward zero, returning the nearest integral value that is not larger in magnitude than x.
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);
Parameter | Description |
---|---|
x | Value to truncate. |
The nearest integral value that is not larger in magnitude than x as a floating-point value.
#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; }