C trunc function

The C trunc function is one of the math Function used to return the truncated value of a given number or a specified expression. The syntax of the truncate function in C Programming is

double trunc(double value);

C trunc Function Example

The math trunc Function allows you to find the truncated value of a given number. In this program, We are going to find the truncated value of different numbers, and display the output.

/* trunc in C Programming Example */

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

int main()
{
    printf("\n The Truncated Value of 0.75    = %.2f ", trunc(0.75));
    printf("\n The Truncated Value of 15.25   = %.2f ", trunc(15.25));
    printf("\n The Truncated Value of 152.50  = %.2f ", trunc(152.50));
    
    printf("\n The Truncated Value of -14.36  = %.2f ", trunc(-14.36));
    printf("\n The Truncated Value of -26.82  = %.2f ", trunc(-26.82));
    printf("\n The Truncated Value of -90.55  = %.2f \n", trunc(-90.55));
    
    return 0;
}
C trunc function example 1

C truncate Example 2

In this String Function example, we are allowing a user to enter their value. Next, this program uses the truncate function in C to truncate the user-specified value.

/* trunc in C Programming Example */

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

int main()
{
    float number, trunc_Value;
    
    printf(" Please Enter any Numeric Value to Round :  ");
    scanf("%f", &number);
    
    trunc_Value = trunc(number);
    
    printf("\n The Truncated Value of %.2f = %.4f \n", number, trunc_Value);
    
    return 0;
}
 Please Enter any Numeric Value to Round :  234.589

 The Truncated Value of 234.59 = 234.0000