zoukankan      html  css  js  c++  java
  • IOS 四舍五入 进一法 去尾法

    IOS 四舍五入 进一法 去尾法

    float numberToRound;

       int result;

        numberToRound = 4.51;

        result = (int)roundf(numberToRound);

        NSLog(@"roundf(%f) = %d", numberToRound, result); // roundf(4.510000) = 5

        result = (int)ceilf(numberToRound);

        NSLog(@"ceilf(%f) = %d", numberToRound, result); // ceilf(4.510000) = 5

        result = (int)floorf(numberToRound);

        NSLog(@"floorf(%f) = %d", numberToRound, result); // floorf(4.510000) = 4

        numberToRound = 10.49;

        result = (int)roundf(numberToRound);

        NSLog(@"roundf(%f) = %d", numberToRound, result); // roundf(10.490000) = 10

        result = (int)ceilf(numberToRound);

        NSLog(@"ceilf(%f) = %d", numberToRound, result); // ceilf(10.490000) = 11

        result = (int)floorf(numberToRound);

        NSLog(@"floorf(%f) = %d", numberToRound, result); // floorf(10.490000) = 10

        numberToRound = -2.49;

        result = (int)roundf(numberToRound);

        NSLog(@"roundf(%f) = %d", numberToRound, result); // roundf(-2.490000) = -2

        result = (int)ceilf(numberToRound);

        NSLog(@"ceilf(%f) = %d", numberToRound, result); // ceilf(-2.490000) = -2

        result = (int)floorf(numberToRound);

        NSLog(@"floorf(%f) = %d", numberToRound, result); // floorf(-2.490000) = -3

        numberToRound = -3.51;

        result = (int)roundf(numberToRound);

        NSLog(@"roundf(%f) = %d", numberToRound, result); // roundf(-3.510000) = -4

        result = (int)ceilf(numberToRound);

        NSLog(@"ceilf(%f) = %d", numberToRound, result); // ceilf(-3.510000) = -3

        result = (int)floorf(numberToRound);

        NSLog(@"floorf(%f) = %d", numberToRound, result); // floorf(-3.510000) = -4

  • 相关阅读:
    Mac Office2016 安装及破解
    Axure 下载安装
    MacBook Pro常用快捷键
    MySQL 关于case when结合group by用时的写法举例
    RFID第二次作业
    Javascript函数柯里化(curry)
    binarySearch二分查找——Javascript实现
    KMP算法——Javascript实现
    从输入 URL 到页面加载完成的过程中都发生了什么事情?
    丁又专老师作业——Java检测代码
  • 原文地址:https://www.cnblogs.com/fengfeng159/p/11357998.html
Copyright © 2011-2022 走看看