0

我有以下内容:

NSLog(@"Total: $%.2f", paymentsToday);

它当前显示:

$16000.00

如何让它显示:

$16,000.00
4

2 回答 2

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);
于 2012-11-18T00:48:27.390 回答
0

使用 NSNumberFormatter 设置货币格式:

    NSNumberFormatter* formatter=[[NSNumberFormatter alloc]init];
    [formatter setNumberStyle: NSNumberFormatterCurrencyStyle];
    NSLog(@"%@",[formatter stringFromNumber: @(paymentsToday)]);
于 2012-11-18T00:45:27.493 回答