在iPhone应用程序中,我想打印以“,”
分隔的十进制值即.2392890应显示为2,392,890
我从SQLite数据库中获取这些数字
答案 0 :(得分:0)
这是solution
//American number format - with comma sepparators between thousands
NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[numberFormatter setFormat:@"#,###"];
NSNumber *averageResponseTime = [NSNumber numberWithInt:123456789];
//If you print next thing
[NSString stringWithFormat: @"%@ms",[numberFormatter stringForObjectValue:averageResponseTime]];
//You will get 123,456,789
答案 1 :(得分:0)
将您的号码传递给以下功能以获得格式化输出。
-(NSString*)getFormattedString:(double)pDoubleValue
{
NSNumber *doubleNumber = [NSNumber numberWithDouble:pDoubleValue];
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
NSString *formattedOutput = [formatter stringFromNumber:doubleNumber];
[formatter release];
return formattedOutput;
}
希望它有所帮助。