C++里面,取整的函数是什么?

来源:百度知道 编辑:UC知道 时间:2024/05/04 22:12:51

#include<math.h>
double ceil(double x) //向上取整

double floor(double x) //向下取整

也可以用数据类型强制转换,那要看数据的大小
可以用int()或long()
比如int(104.23) = 104

abs(n/7)表示取整
Delphi里有: Int(n/7), Round(n/7), Trunc(n/7). 前一个是实型, 后二个为整型. Round为四舍五入取整, Trunc为截断取整.
#include<math.h>
double ceil(double x) //向上取整
double floor(double x) //向下取整
也可以用数据类型强制转换,那要看数据的大小
可以用int()或long()
比如int(104.2) = 104

abs(n/7)表示取整

Delphi里有: Int(n/7), Round(n/7), Trunc(n/7). 前一个是实型, 后二个为整型. Round为四舍五入取整, Trunc为截断取整.

取整的函数其实是一个类型转换的问题:

比如:int a=(int)2.12;

这个时候的a就等于2

ceil()和floor()
ceil向上取整
floor向下取整