trunc(),truncf(),truncl()用C语言
在这里,我们将看到三个功能。这些功能trunc(),truncf()和truncl()。这些函数用于将浮点值转换为截断形式。
该trunc()方法
此函数用于截断双精度型值。并且仅返回整数部分。语法如下。
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\n",a);
printf("The value of a: %lf\n",b);
}输出结果
The value of a: 53.000000 The value of a: 75.000000
该truncf()方法
此函数用于截断float类型值。并且仅返回整数部分。语法如下。
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\n",a);
printf("The value of a: %f\n",b);
}输出结果
The value of a: 53.000000 The value of a: 75.000000
该truncl()方法
这就像trunc()或truncf()。但主要区别在于,此函数用于截断longdouble类型值。并且仅返回整数部分。
语法如下。
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\n",a);
printf("The value of a: %Lf\n",b);
}输出结果
The value of a: 53547.000000 The value of a: 78547.000000
热门推荐
10 诗词送行祝福语大全简短
11 新房开工吉日祝福语简短
12 50多岁生日简短祝福语
13 安徽疫情祝福语简短英语
14 农民朋友发财祝福语简短
15 对生活祝福语简短精辟
16 搬家词简短祝福语朋友
17 女神结婚快乐祝福语简短
18 文学短句祝福语大全简短