iOS float转换为int并就近取整的问题
2015-11-18 15:17
483 查看
if (duration ==
0) {
duration =
0.03; //(gif delay time default is 0.1)
}
NSLog(@"the delay is %f",
duration);
NSLog(@"the duration * 100 is %f",
duration * 100);
NSUInteger interValue =
roundf(duration *
100);
NSLog(@"the roundf is %lu", (unsigned
long)interValue);
size_t delayTime = (int)( (duration *
1000) / 10 );
将一个float转换为int并就近取整的问题 函数round(), roundf(), lround(), 和lroundf()
float fractionalPage = _scrollVIew.contentOffset.x / pageWidth ;
NSInteger nearestNumber = lround(fractionalPage) ;
extern float ceilf(float);
extern double ceil(double);
extern long double ceill(long double);
extern float floorf(float);
extern double floor(double);
extern long double floorl(longdouble);
extern float roundf(float);
extern double round(double);
extern long double roundl(longdouble);
round:如果参数是小数,则求本身的四舍五入。
ceil:如果参数是小数,则求最小的整数但不小于本身.
floor:如果参数是小数,则求最大的整数但不大于本身.
Example:如何值是3.4的话,则
3.4 -- round 3.000000
-- ceil 4.000000
-- floor 3.00000
CGRectMake(floorf(self.view.bounds.size.width*0.5f -39.f*0.5f),self.view.bounds.size.height -57, 39, 39)
其中floorf(self.view.bounds.size.width*0.5f -39.f*0.5f)返回值为
140.000000这种形式
相关文章推荐
- iOS_Xcode7.0_真机调试出现"Could not find Developer Disk Image"
- IOS崩溃异常的处理
- iOS学笔记本45- TTTAttributedLabel 使用方法
- iOS开发库的列表
- 实现iOS7以前的TableViewGroupStyle的方法。
- iOS viewDidLayoutSubviews,viewdidload
- 苹果开发者账号申请流程--企业
- iOS审核秘籍:应用内容检查大法
- IOS6和IOS7的适配问题
- iOS应用发布中的一些细节
- iOS开发代码自动布局NSLayoutConstraint
- iOS GCD创建标准定时器,进入后台后任可继续定时,无需开启后台任务
- 利用NSCache提升效率
- iOS ---对json数组的解析
- nagios_client_V2_sh
- iOS: Crash文件解析
- IOS-使用系统默认声音、震动
- iOS开发 -- 添加自定义ttf字体的方法
- iOS菜鸟之苹果开发者账号的注册
- 自定义iOS下拉框