
这里我们将看到三个函数。这些函数是 trunc()、truncf() 和 truncl()。这些函数用于将浮点值转换为截断形式。
该函数用于截断 double 类型值。并且只返回整数部分。语法如下。
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
此函数用于截断浮点类型的值,并仅返回整数部分。语法如下所示。
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
这类似于 trunc() 或 truncf()。但主要区别在于,该函数用于截断 long double 类型值。并且只返回整数部分。
立即学习“C语言免费学习笔记(深入)”;
语法如下。
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
以上就是在C语言中,trunc()表示截断函数,truncf()表示截断函数(单精度),truncl()表示截断函数(长双精度)的详细内容,更多请关注php中文网其它相关文章!
C语言怎么学习?C语言怎么入门?C语言在哪学?C语言怎么学才快?不用担心,这里为大家提供了C语言速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号