码迷,mamicode.com
首页 > 移动开发 > 详细

IOS 四舍五入 进一法 去尾法

时间:2016-08-01 11:55:27      阅读:736      评论:0      收藏:0      [点我收藏+]

标签:

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

IOS 四舍五入 进一法 去尾法

标签:

原文地址:http://www.cnblogs.com/yujidewu/p/5724966.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!