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. Why are dashes preferred for CSS selectors / HTML attributes?

    Why are dashes preferred for CSS selectors / HTML attributes? I use dashes because I don't have to h ...

  2. layer的iframe弹框中父子元素的传值

    项目中,左侧导航树,右侧是 iframe 嵌套的页面,在右侧页面中又有layer弹框,可以说是有两层 iframe 框架. 所以查询网上的parent什么的方法都不能用.自己摸索的下面的方法: 1.父 ...

  3. Elasticsearch 6.2.3版本 执行聚合报错 Fielddata is disabled on text fields by default

    背景说明 执行<Elasticsearch 权威指南>的示例,在执行聚合查询的时候,报错 Fielddata is disabled on text fields by default. ...

  4. python虚拟环境mkvirtualenv使用

    安装virtualenvwrapper  pip install virtualenvwrapper   修改默认虚拟环境目录: 环境变量中新建: 变量名:WORKON_HOME 变量值:目录位置 ( ...

  5. mysql 8.0.12 安装配置方法图文教程

    一.安装 1.从网上下载MySQL8.0.12版本,下载地址 2. 下载完成后解压 我解压的路径是:D:\Java\mysql-8.0.12-winx64 3. 配置文件 首先在解压的路径下查看是否含 ...

  6. 关于JS的prototype详解

    JavaScript面向对象 构造函数和原型链 首先,我们要先了解一下类的概念,JavaScript 本身是一种面向对象的语言,它所涉及的元素根据其属性的不同都依附于某一个特定的类.我们所常见的类包括 ...

  7. CTF—攻防练习之HTTP—SQl注入(get)

    攻击机:192.168.32.152 靶机 :192.168.32.157 扫描靶机扫端口: 开放了ssh和80看下ssh版本有没有漏洞,searchsplot下,没有发现 dirb扫描下目录,有个a ...

  8. django设置mysql为数据库笔记

    1,guest/settings.py中加上 import pymysql pymysql.install_as_MySQLdb() 安装好pymysql 2,guest/settings.py的DA ...

  9. python学习之面向对象(四)

    6.9 反射 反射是非常重要的内置函数之一. 反射是通过字符串去操作对象相关的属性,这里的对象包括:实列,类,当前模块,其他模块. 主要的四个函数: 查看: hasattr(对象,待查内容的字符串形式 ...

  10. docker搭建环境的时候常用的命令有哪些

    1.docker搭建环境的时候常用的命令有哪些 docker如果要删除镜像,现在停止container docker ps 查询正在运行的镜像docker stop +containerid停止后再删 ...