objective-c - 如何四舍五入浮点值?

标签 objective-c

Possible Duplicate:
Rounding numbers in Objective-C

在 Objective-c 中如何对浮点值进行四舍五入?

最佳答案

除了其他答案:

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/

相关文章:

ios - 用 UITextField 替换 UiNavigationItem.Title 的错误布局

objective-c - 如何有条件地将框架包含在 Xcode 项目中?

objective-c - <CFData 0x100516c60 [0x7fff71adaea0]>{长度 = 6,容量 = 6,字节 = 0x0022412b03ad}

objective-c - presentModalViewController 未被释放

ios - 将 [NSThread sleepForTimeInterval :5] line usage cause App to be reject by Apple Verification?

ios - 如何修复 "malloc: can' t 保护区域的 poSTLude 保护页面“iOS 上的警告

ios - dispacth_sync与dispatch_async:iOS JSON解析

ios - 当 pickerView 出现时,UITextField 中的文本向左移动

iphone - Cocos2D随机 Sprite 运动

ios - 如何使用 Object-C 设置 BSImagePickerViewController