Home > Article > Backend Development > In C language, trunc() represents a truncation function, truncf() represents a truncation function (single precision), and truncl() represents a truncation function (long double precision).
Here we will see three functions. These functions are trunc(), truncf(), and truncl(). These functions are used to convert floating point values into truncated form.
This function is used to truncate double type values. And only the integer part is returned. The syntax is as follows.
double trunc(double argument)
#include <stdio.h> #include <math.h> main() { double a, b, x, y; x = 53.26; y = 75.86; a = trunc(x); b = trunc(y); printf("The value of a: %lf</p><p>",a); printf("The value of a: %lf</p><p>",b); }
The value of a: 53.000000 The value of a: 75.000000
This function is used to truncate the value of floating point type and return only the integer part. The syntax is as follows. The Chinese translation of
float tuncf(float argument)
#include <stdio.h> #include <math.h> main() { float a, b, x, y; x = 53.26; y = 75.86; a = truncf(x); b = truncf(y); printf("The value of a: %f</p><p>",a); printf("The value of a: %f</p><p>",b); }
The value of a: 53.000000 The value of a: 75.000000
This is similar to trunc( ) or truncf(). But the main difference is that this function is used to truncate long double type values. And only the integer part is returned.
The syntax is as follows.
long double truncl(long double argument)
#include <stdio.h> #include <math.h> main() { long double a, b, x, y; x = 53547.55555555555; y = 78547.55555555523; a = truncl(x); b = truncl(y); printf("The value of a: %Lf</p><p>",a); printf("The value of a: %Lf</p><p>",b); }
The value of a: 53547.000000 The value of a: 78547.000000
The above is the detailed content of In C language, trunc() represents a truncation function, truncf() represents a truncation function (single precision), and truncl() represents a truncation function (long double precision).. For more information, please follow other related articles on the PHP Chinese website!