floor()函数 向下取整 ceil()函数向上取整

floor(x)  is the largest integer not greater than x , 也就是,floor(x) 返回的是小于等于x的所有整数中最大的整数,简单的说,就是去掉x的小数部分的整数
ceil(x)  is the smallest integer not less than x,也就是,ceil(x) 返回的是大于等于x的所有整数中最小的整数,简单的说,就是如果x是整数,则返回该数,如果x不是整数,则不管小数部分是多少,都进一位然后返回。

例如:
floor(3.2)= 3;
ceil(3.2)= 4;
floor(4)= 4;
ceil(4)= 4;

// 1.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<iostream>
using namespace std;

int main()
{
int a = 11;
float b = 3.0;

cout << ceil(a / b) << endl;
cout << floor(a / b) << endl;
return 0;
}

原文地址:https://www.cnblogs.com/lsh123/p/6290898.html