I have an iPhone app and I want to display a price. So I use these lines of code:
我有一个iPhone应用程序,我想显示价格。所以我使用这些代码行:
NSNumberFormatter *price = [[NSNumberFormatter alloc] init];
[price setNumberStyle:NSNumberFormatterCurrencyStyle];
[price setCurrencyCode:@"USD"];
What I want is only the price, formatted for the currencyCode
but in my case without USD
. So instead of 30,00 $
, I want to have only 30,00
without $
.
我想要的只是为currencyCode格式化的价格,但在没有USD的情况下。所以不是30,00美元,我想只有30,00没有$。
How can I do this?
我怎样才能做到这一点?
Best Regards, Tim.
最诚挚的问候,蒂姆。
3 个解决方案
#1
20
What you're looking to get rid of is the Currency Symbol.
你想要摆脱的是货币符号。
[price setCurrencySymbol:@""];
#2
3
You can use the setCurrencySymbol to an empty string which should do the trick:
您可以将setCurrencySymbol用于一个空字符串,它应该可以解决这个问题:
[price setCurrencySymbol:@""];
Please keep in mind that this only sets the local currency code and it might not work with foreign currencies.
请注意,这仅设置本地货币代码,并且可能无法使用外币。
#3
1
Here's a way to do it while keeping the correct locale formatting for the symbol:
这是一种在保持符号的正确语言环境格式的同时执行此操作的方法:
_fmt.positiveFormat = [_fmt.positiveFormat
stringByReplacingOccurrencesOfString:@"¤" withString:@""];
_fmt.negativeFormat = [_fmt.negativeFormat
stringByReplacingOccurrencesOfString:@"¤" withString:@""];
The ¤ character is used in the currency formats for the currency symbol. If you replace the currency symbol as suggested in some of the other answers, the formatter does a US standard format for the number (AFAIK - tested in iOS 4 and 5 in the USA). You'll need to do this replacement after setting the locale for the formatter. Try with the currency code HUF which does not have pennies.
¤字符用于货币符号的货币格式。如果您按照某些其他答案中的建议替换货币符号,则格式化程序会为该号码执行美国标准格式(AFAIK - 在iOS 4和5中在美国测试)。设置格式化程序的语言环境后,您需要执行此替换。尝试使用没有便士的货币代码HUF。
#1
20
What you're looking to get rid of is the Currency Symbol.
你想要摆脱的是货币符号。
[price setCurrencySymbol:@""];
#2
3
You can use the setCurrencySymbol to an empty string which should do the trick:
您可以将setCurrencySymbol用于一个空字符串,它应该可以解决这个问题:
[price setCurrencySymbol:@""];
Please keep in mind that this only sets the local currency code and it might not work with foreign currencies.
请注意,这仅设置本地货币代码,并且可能无法使用外币。
#3
1
Here's a way to do it while keeping the correct locale formatting for the symbol:
这是一种在保持符号的正确语言环境格式的同时执行此操作的方法:
_fmt.positiveFormat = [_fmt.positiveFormat
stringByReplacingOccurrencesOfString:@"¤" withString:@""];
_fmt.negativeFormat = [_fmt.negativeFormat
stringByReplacingOccurrencesOfString:@"¤" withString:@""];
The ¤ character is used in the currency formats for the currency symbol. If you replace the currency symbol as suggested in some of the other answers, the formatter does a US standard format for the number (AFAIK - tested in iOS 4 and 5 in the USA). You'll need to do this replacement after setting the locale for the formatter. Try with the currency code HUF which does not have pennies.
¤字符用于货币符号的货币格式。如果您按照某些其他答案中的建议替换货币符号,则格式化程序会为该号码执行美国标准格式(AFAIK - 在iOS 4和5中在美国测试)。设置格式化程序的语言环境后,您需要执行此替换。尝试使用没有便士的货币代码HUF。