对于数据的取整是经常需要考虑的 现在总结如下

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    double a=1.5;
    cout<<ceil(a)<<endl;   //向上取整
    cout<<floor(a)<<endl;   //向下取整
    cout<<round(a)<<endl;   //四舍五入
    //不使用函数   
    cout<<(int)a<<endl;  //向下取整
    cout<<(a>(int)a?(int)a+1:(int)a)<<endl;   //向上取整
    cout<<(int)(a+0.5)<<endl;//四舍五入
    return 0;
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案