我有以下内容:
NSLog(@"Total: $%.2f", paymentsToday);
目前显示:
$16000.00
如何让它显示:
$16,000.00
答案 0 :(得分:3)
您应该使用NSNumberFormatter。
这应该可以解决问题:
NSNumberFormatter *priceFormatter = [[NSNumberFormatter alloc] init];
[priceFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[priceFormatter setCurrencyCode:@"USD"];
[priceFormatter setCurrencySymbol:@"$"];
NSString *formattedOutput = [priceFormatter stringFromNumber:[NSNumber numberWithFloat: paymentsToday]];
NSLog(@"Total: %@", formattedOutput);
答案 1 :(得分:0)
使用NSNumberFormatter设置货币格式:
NSNumberFormatter* formatter=[[NSNumberFormatter alloc]init];
[formatter setNumberStyle: NSNumberFormatterCurrencyStyle];
NSLog(@"%@",[formatter stringFromNumber: @(paymentsToday)]);