- (void)display{
/**
* 方法1(正则表达式)
*/
NSString *regexZero = @"[0]$";
NSString *regexDot = @"[.]$";
NSPredicate *predZero = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regexZero];
NSPredicate *predDot = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regexDot];
while ([predZero evaluateWithObject:_numTemp] || [predDot evaluateWithObject:_numTemp]) {
_numTemp = [_numTemp substringToIndex:_numTemp.length - 1];
}
/**
方法2 NSString * testNumber = _numTemp;
NSString * outNumber = [NSStringstringWithFormat:@"%@",@(testNumber.floatValue)];
**/
/** * 方法3 */// while ([[_numTemp substringFromIndex:_numTemp.length - 1] isEqualToString:@"0"] || [[_numTemp substringFromIndex:_numTemp.length - 1] isEqualToString:@"."]) {// _numTemp = [_numTemp substringToIndex:_numTemp.length - 1];// } [self.numDisplay setText:[NSString stringWithFormat:@"%@",_numTemp]];
}
这篇博客介绍了如何使用NSString处理浮点数时,去除小数点后面多余的0,确保显示的数字格式正确。
2万+

被折叠的 条评论
为什么被折叠?



