数字转字符串,带千位符(逗号)

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

- (NSString*) numberToMathString:(float) num
{
    NSArray * array = [[NSString stringWithFormat:@"%.2f",num/100] componentsSeparatedByString:@"."];
    
    int len = [array[0] length];
    int x = len%3;
    int y = len/3;
    int dotNumber = y;
    
    if (x == 0)
    {
        dotNumber -= 1;
        x = 3;
    }
    NSMutableString * rs = [@"" mutableCopy];
    
    [rs appendString:[array[0] substringWithRange:NSMakeRange(0, x)]];
    
    for (int i=0; i<dotNumber; i++)
    {
        [rs appendString:@","];
        [rs appendString:[array[0] substringWithRange:NSMakeRange(x + i*3, 3)]];
    }
    [rs appendString:@"."];
    [rs appendString:array[1]];
    
    return rs;
}