1. /

//Test "/"
    cout << "Test \"/\"!" << endl;
    cout << "7   / 2   = " << 7/2 << endl;      //3
    cout << "7   / 2.0 = " << 7/2.0 << endl;    //3.5
    cout << "7.0 / 2   = " << 7.0/2 << endl;    //3.5
    cout << "7.0 / 2.0 = " << 7.0/2.0 << endl; //3.5
    cout << "7   / 3   = " << 7/3 << endl;      //2
    cout << endl;

2. %
    //Test "%"
    cout << "Test \"%\"!" << endl;
    cout << "9   % 3   = " << 9%3 << endl;      //0
    cout << "9   % 4   = " << 9%4 << endl;      //1
    //cout << "9.0 % 3   = " << 9.0%3 << endl;
    //cout << "9   % 3.0 = " << 9%3.0 << endl;
    cout << endl;

3. 四舍五入
    //Test round()
    cout << "Test \"四舍五入\"!" << endl;
    double dRoundA = 1.4;
    double dRoundB = 1.6;
    double dRoundLowA = -1.4;
    double dRoundLowB = -1.6;
    double dRoundLowC = 0.0;
    cout << dRoundA << " = " << RoundEx(dRoundA) << endl;         //1
    cout << dRoundB << " = " << RoundEx(dRoundB) << endl;         //2
    cout << dRoundLowA << " = " << RoundEx(dRoundLowA) << endl;   //-1
    cout << dRoundLowB << " = " << RoundEx(dRoundLowB) << endl;   //-2
    cout << dRoundLowC << " = " << RoundEx(dRoundLowC) << endl;   //0
    cout << endl;

double RoundEx(const double& dInput)
{
    double dIn = dInput;
    if (dInput >= 0.0)    //???
    {
        return int(dIn + 0.5);
    } 
    else
    {
        return int(dIn - 0.5);
    }
}

4. ceil() 向上取整
    //Test ceil() 向上取整
    cout << "Test ceil() 向上取整!" << endl; 
    cout << "ceil 1.2 = " << ceil(1.2) << endl;      //2
    cout << "ceil 1.8 = " << ceil(1.8) << endl;      //2
    cout << "ceil -1.2 = " << ceil(-1.2) << endl;    //-1
    cout << "ceil -1.8 = " << ceil(-1.8) << endl;    //-1
    cout << "ceil 0.0 = " << ceil(0.0) << endl;      //0
    cout << endl;

5. floor() 向下取整
    //Test floor() 向下取整
    cout << "Test floor() 向下取整!" << endl;
    cout << "floor 1.2 = " << floor(1.2) << endl;    //1
    cout << "floor 1.8 = " << floor(1.8) << endl;    //1
    cout << "floor -1.2 = " << floor(-1.2) << endl; //-2
    cout << "floor -1.8 = " << floor(-1.8) << endl; //-2
    cout << "floor 0.0 = " << floor(0.0) << endl;    //0
    cout << endl;

ios / % 四舍五入 向上取整(ceil()) 向下取整(floor())的更多相关文章

  1. c++ / % 四舍五入 向上取整ceil 向下取整floor

     / % 四舍五入 向上取整ceil 向下取整floor #include <math.h> double floor(double x); float floorf(float x); ...

  2. python(50):python 向上取整 ceil 向下取整 floor 四舍五入 round

    取整:ceil 向下取整:floor 四舍五入:round 使用如下:

  3. python 向上取整ceil 向下取整floor 四舍五入round

    #encoding:utf-8 import math #向上取整 http://www.manongjc.com/article/1335.html print "math.ceil--- ...

  4. js 向上取整、向下取整、四舍五入

      js 向上取整.向下取整.四舍五入 CreateTime--2018年4月14日11:31:21 Author:Marydon // 1.只保留整数部分(丢弃小数部分) parseInt(5.12 ...

  5. Oracle四舍五入,向上取整,向下取整

    用oracle sql对数字进行操作: 取上取整.向下取整.保留N位小数.四舍五入.数字格式化 取整(向下取整): select floor(5.534) from dual; select trun ...

  6. c# 小数四舍五入,向上取整,向下取整,见角进元保留多个小数位数

    /// <summary> /// 实现数据的四舍五入法 /// </summary> /// <param name="v">要进行处理的数据 ...

  7. Oracle - 数字处理 - 取上取整、向下取整、保留N位小数、四舍五入、数字格式化

    用oracle sql对数字进行操作: 取上取整.向下取整.保留N位小数.四舍五入.数字格式化 取整(向下取整): select floor(5.534) from dual; select trun ...

  8. PHP取整,四舍五入取整、向上取整、向下取整、小数截取

    PHP取整数函数常用的四种方法: 1.直接取整,舍弃小数,保留整数:intval(): 2.四舍五入取整:round(): 3.向上取整,有小数就加1:ceil(): 4.向下取整:floor(). ...

  9. Python 之 向上取整、向下取整以及四舍五入函数

    import math f = 11.2 print math.ceil(f) #向上取整 print math.floor(f) #向下取整 print round(f) #四舍五入 #这三个函数的 ...

随机推荐

  1. js创建对象的6种方式总结

    1.new 操作符 + Object 创建对象 var person = new Object(); person.name = "lisi"; person.age = 21; ...

  2. 非均匀B样条离散点的加密与平滑

    非均匀B样条离散点的加密与平滑 离散点的预处理是点云网格化很关键的一步,主要就是离散点的平滑.孔洞修补:本文是基于非均匀B样条基函数进行离散点云的加密和平滑的,一下为初步实现结果. 算法步骤: 1.数 ...

  3. D5(太长了md没写完)

    动态规划 三种常见实现方法 对于一个斐波那契数列,我们想要求第n项的值,就需要一项一项的递归来求 来看代码 f[o] = 0; f[1] = 1; for (int i = 2; i <= n; ...

  4. 开源之TinyPinyin

    适用于Java和Android的快速.低内存占用的汉字转拼音库. https://github.com/promeG/TinyPinyin

  5. 删除delphi组件TStringlist中的重复项目

    https://blog.csdn.net/ozhy111/article/details/87975663 删除delphi组件TStringlist中的重复项目 2019年02月27日 15:41 ...

  6. Ubuntu基础设定:openssh-server安装和使用

    记录一下Ubuntu17.10的openssh-server的安装和使用.安装之后就可以使用ssh登陆Ubuntu了,所以是Ubuntu的基础设定之一. 事前准备 Ubuntu版本:17.10 dev ...

  7. 英特尔® Open Image Denoise 库有助于节省时间,提高质量

    在使用光线跟踪增强真实性与沉浸感时,游戏开发人员面临复杂的权衡.为了克服一系列挑战,英特尔创建了使用光线跟踪进行图像渲染的一整套解决方案,包含高性能开源滤波器.该解决方案已发布测试版,被集成至 Uni ...

  8. win10更新导致chrome打开网页速度太慢

    升级win10之后如果出现chrome内核的浏览器网页总是打不开 打开很慢 而ie和edge是可以正常访问的 用这个方法可以 我弄了几天终于 搞好了 我直接转载过来了 近期,工程师收到大量反馈360浏 ...

  9. 关于confusion_matrix()返回的矩阵的索引顺序(类别顺序)

    转载至:https://blog.csdn.net/m0_38061927/article/details/77198990 1.混淆矩阵 混淆矩阵是机器学习中总结分类模型预测结果的情形分析表,以矩阵 ...

  10. 数据挖掘竞赛kaggle初战——泰坦尼克号生还预测

    1.题目 这道题目的地址在https://www.kaggle.com/c/titanic,题目要求大致是给出一部分泰坦尼克号乘船人员的信息与最后生还情况,利用这些数据,使用机器学习的算法,来分析预测 ...