美文网首页
数字字符串加入逗号位数分隔

数字字符串加入逗号位数分隔

作者: JohnDEEEN | 来源:发表于2015-07-30 16:18 被阅读0次

    -(NSString *)countNumAndChangeformat:(NSString *)num

    {

    int count = 0;

    long long int a = num.longLongValue;

    while (a != 0) {

    count++;

    a /= 10;    }

    NSMutableString *string = [NSMutableString stringWithString:num];

    NSMutableString *newstring = [NSMutableString string];

    while (count > 3) {

    count -= 3;

    NSRange rang = NSMakeRange(string.length - 3, 3);

    NSString *str = [string substringWithRange:rang];

    [newstring insertString:str atIndex:0];

    [newstring insertString:@"," atIndex:0];

    [string deleteCharactersInRange:rang];

    }

    [newstring insertString:string atIndex:0];

    return newstring;

    }

    相关文章

      网友评论

          本文标题:数字字符串加入逗号位数分隔

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