C++ cmath trunc() function
Example
Truncate numbers:
cout << trunc(0.60);
cout << trunc(0.40);
cout << trunc(5);
cout << trunc(5.1);
cout << trunc(-5.1);
cout << 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 <cmath>
header file.
Syntax
One of the following:
trunc(double number);
trunc(float number);
Parameter Values
Parameter | Description |
---|---|
number | Required. Specifies a number. If the number is an integer type then it will be treated as a double . |
Technical Details
Returns: | A float value (if the argument is float) or double value (in any other case) representing the integer part of a number. |
---|