美文网首页
iOS 处理金额字符串插入逗号

iOS 处理金额字符串插入逗号

作者: 翻滚的炒勺2013 | 来源:发表于2017-09-18 23:08 被阅读44次

    直接调用即可

    - (NSString *)hanleNums:(NSString *)numbers{
        NSString *str = [numbers substringWithRange:NSMakeRange(numbers.length%3, numbers.length-numbers.length%3)];
        NSString *strs = [numbers substringWithRange:NSMakeRange(0, numbers.length%3)];
        for (int  i =0; i < str.length; i =i+3) {
            NSString *sss = [str substringWithRange:NSMakeRange(i, 3)];
            strs = [strs stringByAppendingString:[NSString stringWithFormat:@",%@",sss]];
        }
        if ([[strs substringWithRange:NSMakeRange(0, 1)] isEqualToString:@","]) {
            strs = [strs substringWithRange:NSMakeRange(1, strs.length-1)];
        }
        return strs;
    }
    

    相关文章

      网友评论

          本文标题:iOS 处理金额字符串插入逗号

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