C Math trunc() Function
Example
Return the integer part of different numbers:
printf("%f", trunc(0.60));
printf("%f", trunc(0.40));
printf("%f", trunc(5));
printf("%f", trunc(5.1));
printf("%f", trunc(-5.1));
printf("%f", trunc(-5.9));
Try it Yourself »
Definition and Usage
The trunc()
function truncates a number, which means returning only the integer part of the number.
The trunc()
function is defined in the <math.h>
header file.
Syntax
One of the following:
trunc(double number);
Parameter Values
Parameter | Description |
---|---|
number | Required. Specifies a number. |
Technical Details
Returns: | A double value representing the integer part of a number. |
---|