floor(x) 函数

floor(x)函数,向下取整函数,即返回不大于x的最大整数,区别于四舍五入。

例如:

floor(3.14),返回3

floor(3.99),返回3

floor(-3.14),返回-4

floor(-3.99),返回-4

iOS开发中的应用:

UIScrollView计算当前页的算法

NSInteger page=floor((scrollView.contentOffset.x-pageWidth/2)/pageWidth)+1;

 

 
posted @ 2015-08-04 09:59  mooney_wang  阅读(244)  评论(0)    收藏  举报