zoukankan      html  css  js  c++  java
  • 数学运算_基本_01

    Delphi版:http://www.cnblogs.com/CodeSkill/p/7133178.html

    1、浮点数 取整数部分

      直接强制转换即可

      Delphi:Trunc

    2、向下取整 (往值小的方向取) (注意 负数的时候也是往值小的方向取)

      floor  (#include <math.h>)

      Delphi中:floor  (uses Math;)

    3、向上取整 (往值大的方向取) (注意 负数的时候也是往值大的方向取)

      ceil  (#include <math.h>)

      Delphi中:ceil  (uses Math;)

    4、

    5、

    6、测试代码:

    #include <stdio.h>
    #include <math.h>
    
    void main()
    {
        // ZC: 注意,下面 两个是不同的
        printf("%lf , %lf
    ",(double)(17/4), (double)17/4);
    
        double a, b, c;
        a = (double)17 / 4;
        b = floor(a);
        c = ceil(a);
        printf("%lf, %lf, %lf
    ",a, b, c);
    
        a = 17 / 4;// ZC: 这里,实际是将 整数4 赋值给了 a
        b = floor(a);
        c = ceil(a);
        printf("%lf, %lf, %lf
    ",a, b, c);
    
        // 直接取整数 部分
        a = (double)17 / 4;
        b = (double)19 / 4;
        printf("%lf, %lf ==> %d, %d
    ", a, b, (int)a, (int)b);
    }

      6.1、控制台输出:

    4.000000 , 4.250000
    4.250000, 4.000000, 5.000000
    4.000000, 4.000000, 4.000000
    4.250000, 4.750000 ==> 4, 4
    Press any key to continue

    7、

  • 相关阅读:
    [转载]Oracle Golden Gate
    git操作命令
    logger.error完整打印错误堆栈信息
    短网址算法
    YYYY-mm-dd HH:MM:SS大小写解释
    quarz时间配置
    Freemarket语法
    Java NIO:IO与NIO的区别
    idea常用到的命令
    linux 常用命令
  • 原文地址:https://www.cnblogs.com/cppskill/p/7133156.html
Copyright © 2011-2022 走看看