Divide int's and round up in Objective-C

前端 未结 5 845
既然无缘
既然无缘 2021-01-31 01:11

I have 2 int\'s. How do I divide one by the other and then round up afterwards?

5条回答
  •  一生所求
    2021-01-31 01:43

    -(NSInteger)divideAndRoundUp:(NSInteger)a with:(NSInteger)b
    {
      if( a % b != 0 )
      {
        return a / b + 1;
      }
      return a / b;
    }
    

提交回复
热议问题