Javatpoint Logo
Javatpoint Logo

C++ Math trunc()

The function rounds off the given value towards zero and returns the nearest integral value whose magnitude is not greater than the given value.

For example:

Syntax

Suppose a number is 'x'. Syntax would be :

Note: return_type can be float,double or long double.

Parameter

x: The value that can be float,double or long double.

Return value

It returns a rounded value of x.

Example 1

Let's see a simple example when the value of x is positive.

Output:

The value of x is :8.8
Truncated value of x is :8

Example 2

Let's see a simple example when the value of x is negative.

Output:

The value of x is :-3.9
Truncated value of x is:-3

Next TopicC++ Math Functions




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


B.Tech / MCA