- (void) currencyFormat {
double someDouble = 100.00;
NSNumber *currencyValue = [NSNumber numberWithDouble:someDouble];
NSNumberFormatter *formater = [[NSNumberFormatter alloc] init];
[formater setNumberStyle:NSNumberFormatterCurrencyStyle];
NSString *currencyString = [formater stringFromNumber:currencyValue];
NSLog(@"Value = %@",currencyString);
}
我尝试了上面的代码,但它将所有货币符号都作为前缀。 如果我想将它作为后缀放置怎么办?请提出解决方案。
答案 0 :(得分:0)
正如文档所说,NSNumberFormatter
的默认行为正在发生:
指定货币样式格式;例如,在en_US_POSIX中 locale,1234.5678表示为“$ 1234.57”。
如果您想要最后的货币,您可以这样做:
NSNumberFormatter *formater = [[NSNumberFormatter alloc] init];
[formater setPositiveSuffix:formater.currencySymbol];
[formater setNegativeSuffix:formater.currencySymbol];
NSString *currencyString = [formater stringFromNumber:currencyValue];
NSLog(@"Value = %@",currencyString);