您需要繼承NSNumberFormatter:
例子:
@implementation LTNumberFormatter
@synthesize abbreviationForThousands;
@synthesize abbreviationForMillions;
@synthesize abbreviationForBillions;
-(NSString*)stringFromNumber:(NSNumber*)number
{
if (! (abbreviationForThousands || abbreviationForMillions || abbreviationForBillions))
{
return [super stringFromNumber:number];
}
double d = [number doubleValue];
if (abbreviationForBillions && d > 1000000000)
{
return [NSString stringWithFormat:@"%@ %@", [super stringFromNumber:[NSNumber numberWithDouble:d/1000000000]], abbreviationForBillions];
}
if (abbreviationForMillions && d > 1000000)
{
return [NSString stringWithFormat:@"%@ %@", [super stringFromNumber:[NSNumber numberWithDouble:d/1000000]], abbreviationForMillions];
}
if (abbreviationForThousands && d > 1000)
{
return [NSString stringWithFormat:@"%@ %@", [super stringFromNumber:[NSNumber numberWithDouble:d/1000]], abbreviationForThousands];
}
return [super stringFromNumber:number];
}
@end
這不是重複。這不是指文件大小。 –