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. 了解SpringMVC框架及基本工作流程

    传统原生的JSP+Servlet在开发上过程上虽然简单明了,JSP页面传递数据到Servlet,Servlet整理数据(逻辑开发)或者从数据库提取数据接着再转发到JSP页面上,但是其似乎只能止步于此, ...

  2. 30天C#基础巩固------this,base,string中的方法,StringBuilder性能

    这里主要是记录下自己学习笔记,希望有个地方在以后可以看到自己走过的路. 关于之前多态的知识有一个口诀,很好理解里面的override和new,virtual关键字. "new则隐藏,over ...

  3. Razor练习1

    学习ASP.NET MVC, Razor语法必须掌握,这篇学习: Razor code blocks are enclosed in @{ ... }Inline expressions (varia ...

  4. 质数的判断,实现bool IsPrime(int number)

    1.重复输入一个数,判断该数是否是质数,输入q结束?质数的判断用方法来实现bool IsPrime(int number) static void Main(string[] args) { // 要 ...

  5. sql 内连接和外链接

    如表     -------------------------------------------------     table1 | table2 |     ----------------- ...

  6. VS2010下安装Cocos2dx完整教程(原)

    一.本人所使用的Cocos2dx版本(cocos2d-2.1rc0-x-2.1.3),下载地址:http://code.google.com/p/cocos2d-x/downloads/list 当前 ...

  7. 【Linux_Fedora_应用系列】_2_如何安装视频播放器和视频文件解码

    在前面的一篇博文中,我们进行了音乐播放器的安装和解码器的安装.[Linux_Fedora_应用系列]_1_如何安装音乐播放器和mp3解码 这里我们来进行视频播放器的安装.我们还是通过yum方式安装. ...

  8. Maven+Spring+Spring MVC+MyBatis+MySQL,搭建SSM框架环境

    项目建设完成之后的结构: 数据库的表结构如下: 环境建设:搭建Maven环境.Tomcat环境.需要MySql 数据库支持,使用的编程工具Eclipse (这些是前期准备): 开始创建工程: 1.创建 ...

  9. lodash常用方法1--查询

    1.find var _ = require('lodash'); var user1 = { name: 'zhangsan', height: 180, weight: 120 }; var us ...

  10. jQuery cxScroll 间歇式无缝滚动

    版本: jQuery v1.7+ jQuery cxScroll v1.2.2 注意事项: 内部会自动创建 prev 及 next 切换按钮,也可以在外部直接创建,若外部已创建或设置prevBtn: ...