iphone - NSString - float 的最大 1 位小数

标签 iphone objective-c nsstring nsnumberformatter

我想在 NSString 中使用 float 。我使用 stringWithFormat 和 %f 将我的 float 整合到 NSString 中。问题是我只想显示一位小数 (%.1f) 但是当没有小数时我不想显示 '.0' 。

我该怎么做?

谢谢

最佳答案

我用 NSNumberFormatter 和 setMaximumFractionDigits 找到了答案,然后:

[numberFormatter stringFromNumber:myNumber]

感谢大家,尤其是@falconcreek

关于iphone - NSString - float 的最大 1 位小数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2736093/

相关文章:

iphone - PDF ScrollView 不滚动

iphone - 在 Xcode 模拟器中终止应用程序

iphone - iOS : UITableView Reorder control not shown

ios - Twitter API 返回错误 : SSL is required(92)

objective-c - NSNumberFormatter 干扰 NSString intValue

iphone - 僵尸报告 : message sent to deallocated instance

iPhone - 通话屏幕中间的控件是什么?

iphone - 在 TableView 中将项目标记为新添加

ios - 避免致命车祸

ios - 从 NSDictionary 检索数据,引号已经在值周围?