• 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

  • 相关阅读:
    django中间件和常用模块
    django之forms组件
    django和ajax、分页器、批量插入数据
    django之模型层ORM操作
    (专题三)02-1 程序和程序设计流程-选择结构
    (专题三)01 程序和程序设计流程-顺序结构
    (专题二)05 矩阵的存储方式
    (专题二)04 矩阵的处理-矩阵的特征值
    [代码片段]YEAH!连通域标记和计数
    TTL和CMOS
  • 原文地址:https://www.cnblogs.com/yujidewu/p/5724966.html
Copyright © 2020-2023  润新知