如何使用NSNumberFormatter显示货币?

时间:2011-04-16 07:43:19

标签: objective-c xcode nsnumberformatter

我想格式化一个NSNumberFormatter的数字,以便显示为这样的货币:

NSNumberFormatter *numFormatter = [[NSNumberFormatter alloc] init];
NSNumber *myNumber = [NSNumber numberWithDouble:[@"0.058" doubleValue]];

[numFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];

这给了我0,06 €。但我希望它是5,8 ct。有什么想法吗?

1 个答案:

答案 0 :(得分:3)

您可以像这样配置NSNumberFormatter:

NSNumberFormatter *numFormatter = [[NSNumberFormatter alloc] init];
[numFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[numFormatter setCurrencySymbol:@"ct"];
[numFormatter setMultiplier:100];
NSNumber *myNumber = [NSNumber numberWithDouble:[@"0.058" doubleValue]];