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. div随窗口变化设置高度

    window.onscroll = function () { sc(); }; window.onresize = function () { sc(); }; window.onload = fu ...

  2. Is JavaScript a pass-by-reference or pass-by-value language?

    Is JavaScript a pass-by-reference or pass-by-value language? A very detailed explanation about copyi ...

  3. Linux环境快速搭建elasticsearch6.5.4集群和Head插件

    https://blog.csdn.net/boling_cavalry/article/details/86358716

  4. wls应用命令部署与卸载

    1.查看wls节点运行状态 [root@localhost lib]# jps [root@localhost lib]# ss -tnlp|grep 23705 2.配置wls环境变量 [deplo ...

  5. leetcode 102二叉树的层序遍历

    5月20更新: 使用借助队列实现bfs,定义len记录队列的尺寸直接进行遍历层序 /** * Definition for a binary tree node. * struct TreeNode ...

  6. Ruby小白入门笔记之<Rubymine工具的快捷键>

    智能快捷 Ctrl+Alt+G:弹出Generate Ctrl+Alt+L:格式化代码 Alt+F1:切换视图(Project, Structure, etc.). Alt+F2:弹出预览窗口,可选择 ...

  7. django路由的二级分发

    基于二级分发设计url路由 path('index/', views.index), path('index/', ([ path('test01/', test01), path('test02/' ...

  8. Java学习笔记之Iterator和ListIterator

    原文:https://blog.csdn.net/GongchuangSu/article/details/51514380 Iterator接口是对collection进行迭代的迭代器,ListIt ...

  9. Selenium 2自动化测试实战5(模块调用)

    一.模块调用 1.创建一个目录project,并且在目录下面创建两个文件 project/ 一 pub.py L一 count.py 在pub.py文件中创建add函数. #pub.py def ad ...

  10. SparseLDA算法

    2 SparseLDA算法 本章将介绍一种Gibbs Sampling算法的加速算法——SparseLDA [9],它主要利用LDA 模型的稀疏性,来达到加速以及节省内存的目的,是一种精确算法(没有近 ...