iPhone->;NSNumberFormatter-不带货币代码的价格
我有一个iPhone应用程序,我想显示一个价格。因此,我使用以下代码行:iPhone->;NSNumberFormatter-不带货币代码的价格,iphone,objective-c,Iphone,Objective C,我有一个iPhone应用程序,我想显示一个价格。因此,我使用以下代码行: NSNumberFormatter *price = [[NSNumberFormatter alloc] init]; [price setNumberStyle:NSNumberFormatterCurrencyStyle]; [price setCurrencyCode:@"USD"]; 我想要的只是价格,格式为currencyCode,但在我的情况下没有USD。 因此,我不想要30,00$,我只想要30,00而不
NSNumberFormatter *price = [[NSNumberFormatter alloc] init];
[price setNumberStyle:NSNumberFormatterCurrencyStyle];
[price setCurrencyCode:@"USD"];
我想要的只是价格,格式为currencyCode
,但在我的情况下没有USD
。
因此,我不想要30,00$
,我只想要30,00
而不想要$
我该怎么做
向您致意,蒂姆。您可以使用设置货币符号来表示空字符串,这应该可以实现以下功能:
[price setCurrencySymbol:@""];
请记住,这只设置了本地货币代码,可能对外币不起作用。您希望去掉的是货币符号
[price setCurrencySymbol:@""];
以下是一种在保持符号的正确区域设置格式的同时执行此操作的方法:
_fmt.positiveFormat = [_fmt.positiveFormat
stringByReplacingOccurrencesOfString:@"¤" withString:@""];
_fmt.negativeFormat = [_fmt.negativeFormat
stringByReplacingOccurrencesOfString:@"¤" withString:@""];
·字符用于货币符号的货币格式。如果您按照其他一些答案中的建议替换货币符号,格式化程序会对数字使用美国标准格式(AFAIK-在美国的iOS 4和iOS 5中测试)。在设置格式化程序的区域设置后,需要进行此替换。尝试使用没有便士的货币代码HUF。但届时将使用哪种货币样式?因为有些国家将编写
而不是,
。您还应该能够使用:[price setInternationalCurrencySymbol:@”“]处理国际货币符号;对于da_da locale,它会输出带有空格后缀的数字,如“1.000,00”。对于Danish等语言环境,请使用setCurrencyGroupingSeparator:&setCurrencyDecimalSeparator:。您可以通过设置负值和正值uffix来删除空格后缀。