Divide int's and round up in Objective-C

前端 未结 5 846
既然无缘
既然无缘 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:46

    What about:

    float A,B; // this variables have to be floats!
    int result = floor(A/B); // rounded down
    int result = ceil(A/B); // rounded up
    

提交回复
热议问题