[c++]小数处理ceil, floor, round

1.去尾法

double x = 3.2;
int y = x;

2.向上取整(不小于x的最小整数)

#include

float x = ceil(2.3);//3.0
float y = ceil(3.4);//4.0
folat z = ceil(-2.3);//-2.0

3.向下取整(不大于x的最大整数)

#include

float x = floor(3.2); //3.0
float y = floor(2.8); //2.0
float z = floor(-3.2); //-4.0

4.四舍五入

#include

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

 

你可能感兴趣的:(c++)