cout<<(int)-2.5;
将输出-2
cout<<(int)2.5;
将输出2
将浮点数转成整数:
引自:http://topic.csdn.net/t/20030919/12/2278146.html
函数形式:
inline bool Check_Integer(double x){ return x == int(x); }
宏定义形式:
#define CHECK(x) ((x) - (int)(x) == 0 ? 1 : 0)
#define CHECK(x) ((x) - (int)(x) <0.00000001 ? 1 : 0)
#define CHECK(x) (((x) == (int)(x)))