最佳答案
除了其他答案:
float theFloat = 1.23456;
int rounded = roundf(theFloat); NSLog(@"%d",rounded);
int roundedUp = ceil(theFloat); NSLog(@"%d",roundedUp);
int roundedDown = floor(theFloat); NSLog(@"%d",roundedDown);
// Note: int can be replaced by float
对于特定小数的四舍五入,请参阅 Alex Kazaev 提到的问题。
关于objective-c - 如何四舍五入浮点值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5594116/