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. ASP.NET MVC WEB API必知必会知识点总结

    一.理解WEB API:提供基于RESTful架构的WEB服务,通过HTTP请求方法(GET, PUT, POST, DELETE)映射到服务器端相应的ACTION方法(CRUD). RESTful架 ...

  2. 《ASP.NET SignalR系列》第五课 在MVC中使用SignalR

    接着上一篇:<ASP.NET SignalR系列>第四课 SignalR自托管(不用IIS) 一.概述 本教程主要阐释了如何在MVC下使用ASP.NET SignalR. 添加Signal ...

  3. 优化MySchool数据库总结

  4. C# 解析html —— 将html转为XHTML,然后利用Xml解析

    呵呵,由于正则不熟,所以另谋出路——利用XML去解析html. 要想将抓取到的数据(直接抓取到的是byte[])  转为XML文档(即XMLDocument对象),有两个要点: 一.判断编码(http ...

  5. 使用Tuple来实现多个Model传送至视图

    前面Insus.NET实现过<使用ViewModel来实现多个Model传送至视图>http://www.cnblogs.com/insus/p/5594134.html 和<使用E ...

  6. 控制器描述者(ControllerDescriptor),行为方法描述者(ActionDescriptor),参数描述者(ParameterDescriptor)的小结

    Model的绑定是在Action方法绑定参数时发生的,这个绑定的参数过程要用到的元数据来自于控制器,行为方法和参数的描述者ContrllerDescriptor,ActionDescriptor和Pa ...

  7. 【Win10开发】关于汉堡菜单-SplitView的用法

    SplitView(汉堡菜单)是win10新加的一种控件,顾名思义,其实就是将视图分割成两部分,废话不多说,下面来介绍一下SplitView的基本用法. 首先介绍几个SplitView经常用到的属性. ...

  8. 关于java jni编译javac javah的问题

    这篇文章是在安卓教程网http://android.662p.com那边分享过来的,文章说得还不错的,希望能够帮到大家的学习. javac  编译class文件命令,需要注意的是当类B中import类 ...

  9. jquery的ajax可以传入的三种参数类型

    在jquery的ajax函数中,可以传入3种类型的数据 1.文本:"uname=alice&mobileIpt=110&birthday=1983-05-12" 2 ...

  10. 从零开始学Python第0周:Python基本介绍(部分内容来源于网络)

    Python入门介绍 一,Python的基本介绍 (1)概要 Python是一种解释型,面向对象,动态数据类型的高级程序设计语言.常被广泛用于处理系统管理任务和web编程.现如今Python已经成为了 ...