Convert float to int in Objective-C

后端 未结 4 519
半阙折子戏
半阙折子戏 2021-02-02 02:18

How can I convert a float to int while rounding up to the next integer? For example, 1.00001 would go to 2 and 1.9999 would go to 2.

4条回答
  •  南方客
    南方客 (楼主)
    2021-02-02 02:54

    if we have float value like 13.123 to convert it into integer like 13

    Code

    float floatnumber=13.123; //you can also use CGFloat instead of float

    NSLog(@"%.f",floatnumber); // use for print in command prompt  
    

提交回复
热议问题