1 方法有强制转换、使用库函数round,ceil,floor等
2 使用示例
#include<stdio.h>
#include<math.h>
int main(){
float f = 12.5;
int a = (int)f;//强制转换 直接取整
int b = round(f);//四舍五入取整
int c = ceil(f);//向上取整
int d = floor(f);//向下取整
printf("a=%d\nb=%d\nc=%d\nd=%d\n", a, b, c, d);
getchar();
return 0;
}
3 运行结果
![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/7af40ad162d9f2d3476f015bafec8a136327cc03?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)