美文网首页
ios中去除小数点后多余的0

ios中去除小数点后多余的0

作者: 潮人花钱不用钱 | 来源:发表于2017-03-30 10:37 被阅读712次
    • (NSString *)removeFloatAllZero:(NSString *)string{
      NSString * testNumber = string;
      NSString * outNumber = [NSString stringWithFormat:@"%@",@(testNumber.floatValue)];
      //价格格式化显示
      NSNumberFormatter * formatter = [[NSNumberFormatter alloc]init];
      formatter.numberStyle = kCFNumberFormatterDecimalStyle;
      NSString * formatterString = [formatter stringFromNumber:[NSNumber numberWithFloat:[outNumber doubleValue]]];
      //获取要截取的字符串位置
      NSRange range = [formatterString rangeOfString:@"."];
      if (range.length >0 ) {
      NSString * result = [formatterString substringFromIndex:range.location];
      if (result.length >= 4) {
      formatterString = [formatterString substringToIndex:formatterString.length - 1];
      }
      }

      return formatterString;
      }

    相关文章

      网友评论

          本文标题:ios中去除小数点后多余的0

          本文链接:https://www.haomeiwen.com/subject/szuuottx.html