我想在 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/