/*
*函数名:insertSymbolToNum
*参数1:Num 需要添加的符号的浮点类型数
*参数2:symbol 添加的符号
*参数3:digit 插入的间隔位数
*/
-(NSString *)insertSymbolToNum:(double)Num withSymbol:(NSString *)symbol withDigit:(int)digit
{
NSMutableString *str = [NSMutableString stringWithFormat:@"%.2f",Num];
NSInteger s = [str rangeOfString:@"."].location;
double x = (double)s/digit;
for (int i = 1; i<=x; i++) {
if (i!=x) {
[str insertString:symbol atIndex:s-i*digit];
}
}
return str;
}
///使用方法
NSString *str = [self insertSymbolToNum:12345.321 withSymbol:@"," withDigit:4];
NSLog(@"str is %@",str);