【发布时间】:2015-04-27 11:04:55
【问题描述】:
我有体重值,它们可以是 75 公斤和 75.5 公斤。
我希望这个值有两种样式:75kg、75.5kg,但不是 75.0kg。我该怎么做?
我有这个解决方案,但我不喜欢它
//show difference in 75 and 75.5 values style
NSString *floatWeight = [NSString stringWithFormat:@"%.1f",weightAtThePoint.floatValue];
NSString *intWeight = [NSString stringWithFormat:@"%.0f.0",weightAtThePoint.floatValue];
NSString *resultWeight;
if ([floatWeight isEqualToString:intWeight]) {
resultWeight = [NSString stringWithFormat:@"%.0f",weightAtThePoint.floatValue];
} else {
resultWeight = floatWeight;
}
【问题讨论】:
-
你想要什么可以解释一下
-
我希望这个值有两种样式:75kg、75.5kg,但不是 75.0kg。
-
有没有任何格式化数字解决方案?
-
你可以试试这个链接stackoverflow.com/questions/560517/…
标签: ios iphone numbers number-formatting