取消小数点后面多余的0
方法一:
NSString * testNumber = @"3.14000000";
NSString * outNumber = [NSString stringWithFormat:@"%@",@(testNumber.floatValue)];
NSLog(@"%@", outNumber);
方法二:
NSString * testNumber = @"3.1400000";
NSString * s = nil;
int offset = testNumber.length - 1;
while (offset)
{
s = [testNumber substringWithRange:NSMakeRange(offset, 1)];
if ([s isEqualToString:@"0"] || [s isEqualToString:@"."])
{
offset--;
}
else
{
break;
}
}
NSString * outNumber = [testNumber substringToIndex:offset+1];
NSLog(@"%@", outNumber);