1.添加一个nsstring分类
网上很多方法都是 nsstring = str = [nsstring stringformate:@"%@",@([str floatValue])]; 这样如果数字很大活着位数很多会产生科学计数,使用自己封装的方法完美解决
-
(NSString *)formatePointZero1:(NSString *)text
{
NSString *numstr = text;
NSArray *array = [numstr componentsSeparatedByString:@"."];
if (array.count == 1) return array[0];if (array.count > 1) {
while(numstr.length > 0){
NSInteger index = numstr.length - 1;
NSString *temp = [numstr substringWithRange:NSMakeRange(index, 1)];
if ([temp isEqualToString:@"0"]){
numstr = [numstr substringWithRange:NSMakeRange(0, index)];
continue;
}
break;
}array = [numstr componentsSeparatedByString:@"."]; if (array.count > 1 && [array[1] isEqualToString:@""]){ numstr = array[0]; }
}
return numstr;
}