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 四舍五入 进一法 去尾法的更多相关文章

  1. JS保留小数 去尾法 进一法 四舍五入法

    //toFixed 四舍五入遇到坑. 1.235.toFixed(2) = 1.23 1.2350001.toFixed(2) = 1.24 //去尾法 Number.prototype.toFloo ...

  2. OC中浮点数转整数的进一法和去尾法

    //去尾法,最小去尾单位为0.000001 floorf(4.1)4 floorf(4.9)4 floorf(4.999999)4 floorf(4.9999999)5 //进一法,最小进位单位为0. ...

  3. php取整的几种方式,四舍五入,舍去法取整,进一法取整

    php取整的几种方式,四舍五入,舍去法取整,进一法取整方式一:round 对浮点数进行四舍五入语法:float round ( float val [, int precision] ) echo r ...

  4. 【PHP】进一法取整、四舍五入取整、忽略小数等的取整数方法大全

    PHP取整数函数常用的四种方法,下面收集了四个函数:经常用到取整的函数,今天小小的总结一下!其实很简单,就是几个函数而已--主要是:ceil,floor,round,intval PHP取整数函数常用 ...

  5. php进一法取整、四舍五入取整、忽略小数等的取整数方法大全

    PHP取整数函数常用的四种方法,下面收集了四个函数:经常用到取整的函数,今天小小的总结一下!其实很简单,就是几个函数而已--主要是:ceil,floor,round,intval PHP取整数函数常用 ...

  6. centos 输入密码正确进不去系统

    国庆长假之后,上班,第一件事就是连接开发服务器进行开发,结果发现死活进不去系统.一开始以为是用户名和密码错误,后来发现怎么输入都是进不去系统,密码输入是肯定正确的. google了一下,发现有人说是密 ...

  7. vs调试断点进不去的解决办法

    原创文章,禁止转载. 断点进不去的解决办法:  确认是debug版本  确认生成了调试信息  确认在编译和连接的工程配置中指定了相同的匹配的pdb文件名,而不是默认的vc100.pdb等名字(无关) ...

  8. DirectWrite文字排版——字符串去尾

    DirectWrite是 DirectX 家族中专门用来做文本处理的部分,主要配合Direct2D进行渲染工作. 一.字符串去尾介绍 在文字渲染中,不免会遇到字符串去尾的需求.字符串去尾指的是:当字符 ...

  9. Android Studio安装后第一次进不去

    Android Studio 安装后第一次进不去,因为检查到有更新的SDK,在下载.但是呢,没有FQ的情况下,无法下载下来,所以就卡住了. 那么解决方案就是让 Android Studio 第一次启动 ...

随机推荐

  1. JS魔法堂:函数重载 之 获取变量的数据类型

    Brief 有时我们需要根据入参的数据类型来决定调用哪个函数实现,就是说所谓的函数重载(function overloading).因为JS没有内置函数重载的特性,正好给机会我们思考和实现一套这样的机 ...

  2. JS魔法堂:从void 0 === undefined说起

    一.前言 当使用coffeescript书写如下代码时 name = person?.name 会被预编译为 ; ,那么void 0到底是什么意思呢?运行得知void 0===undefined为tr ...

  3. PHP的数据类型总结

    最近开始学习php,下面是我总结的数据类型,画的思维导图: 注意:查看图片要调大浏览器的缩放比例(我也不知道为啥图片上传之后显示这么小,不清晰): 上面太大看不清,我就分别截图:

  4. winform控件

    公共控件:1.Button: Enabled - 开始不可用 Visible -不可视(用来设置权限,取用户看不见的值)2.CheckBox .CheckListBox -复选框,复选框组 3.Com ...

  5. asp.net在网站根目录下创建文件夹

    假设要在asp.net网站的根目录下建立文件夹hovertree,C#代码如下: string m_keleyiFolderName = Server.MapPath("/hovertree ...

  6. css3代码让页面倾斜

    教大家一个方法使用CSS把整个网页倾斜,代码只有在支持CSS3.0的浏览器上有效果.目前只有IE9以上版本及firefox高版本支持,其它浏览器没有测试.代码如下 body{ -webkit-tran ...

  7. 关于ajax的同步和异步

    今天在开发中遇到个ajax访问Action 返回json 拼接Html,有时候能显示,有时候显示不出来. 考虑后一定是页面元素加载的问题. 所以把jq ajax设置为同步. 同步意为当访问后台代码时, ...

  8. 【C#】让工具栏ToolStrip能触发焦点控件的Leave、Validating、DataError等事件以验证数据

    ----------------更新:2014-04-21--------------- 蒙doggo兄指教,得知有更好的方法可以代替蹩脚的0尺寸Button法,即调用窗体的验证方法Form.Vali ...

  9. MFC文件操作

    文件操作:二进制文件和文本文件的区别.二进制文件将数据在内存中存在的模式原封不动的搬到文件中,而文本文件是将数据的asc码搬到文件中.首先做一个读写文件的菜单,在CxxView里响应1.C的方式:fw ...

  10. CodeSnippet.info整体技术构架

    CodeSnippet.info整体架构 服务器端 Asp.NET MVC5 考察过MVC6,但是现在MVC6还不成熟,技术上不稳定,很多资料也比较少. 所以网站暂时使用MVC5.当然网站的大部分业务 ...