Objective-C Float Rounding

前端 未结 7 1525
执念已碎
执念已碎 2020-12-16 09:26

How might I round a float to the nearest integer in Objective-C:

Example:

float f = 45.698f;
int rounded = _______;
NSLog(@\"the rounded float is %i\         


        
7条回答
  •  难免孤独
    2020-12-16 09:47

    If in case you want round float value in integer below is the simple method for rounding the float value in objective C.

    int roundedValue = roundf(Your float value);
    

提交回复
热议问题