版权声明:转载请注明出处 https://blog.csdn.net/weixin_40937100/article/details/88597340
1.去尾法
double x = 3.2;
int y = x;
2.向上取整(不小于x的最小整数)
#include<cmath>
float x = ceil(2.3);//3.0
float y = ceil(3.4);//4.0
folat z = ceil(-2.3);//-2.0
3.向下取整(不大于x的最大整数)
#include<cmath>
float x = floor(3.2); //3.0
float y = floor(2.8); //2.0
float z = floor(-3.2); //-4.0
4.四舍五入
#include<cmath>
float x = round(3.4); //3.0
float y = round(3.6); //4.0
float z = round(-2.3); //-2.0
float m = round(-3.9); //-4.0