iPhone 动态更改基于县的货币符号?

发布于 2024-12-21 20:55:33 字数 574 浏览 2 评论 0原文

我想根据用户的本地化更改 iPhone 应用程序中的货币符号。如果我的应用程序在美国运行,我需要更改货币符号“$”。如果应用程序在欧洲国家运行,我们需要将符号更改为“€”,如果应用程序在日本运行,则符号应更改为“日元”,如果应用程序在澳大利亚运行,则符号应为“ $”。通过这种方式,如果应用程序在任何国家/地区运行,则应用程序应该根据本地化更改货币符号。我使用了下面的代码,但是它总是显示在“$”中。我该如何解决这个问题?我该如何测试这个?请帮我。

NSNumberFormatter *currencyFormat = [[NSNumberFormatter alloc] init];
NSLocale *locale = [NSLocale currentLocale];
[currencyFormat setNumberStyle:NSNumberFormatterCurrencyStyle];
[currencyFormat setLocale:locale];
NSLog(@"Amount with symbol: %@", [currencyFormat stringFromNumber:@"10.00"]); 

请帮我。我哪里错了?提前致谢。

I want to change the currency symbols in iPhone app based on user's localization. If my app is working in US i need to change the currency symbol "$". If the app is working in Eroupe countries, we need to change the symbol to "€", if the app is in Japan, the symbol should be change to "¥" and if the app is running in Australia the symbol should be in "$". By this way if the app is running in any country the app should be change the currency sign based on the localizations. I have used this below code but, it always shows in "$". How can i solve this? And also how can i test this? Please help me.

NSNumberFormatter *currencyFormat = [[NSNumberFormatter alloc] init];
NSLocale *locale = [NSLocale currentLocale];
[currencyFormat setNumberStyle:NSNumberFormatterCurrencyStyle];
[currencyFormat setLocale:locale];
NSLog(@"Amount with symbol: %@", [currencyFormat stringFromNumber:@"10.00"]); 

Please help me. Where i am wrong? Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仙气飘飘 2024-12-28 20:55:33

模拟器支持更改本地化,就像在常规设备上一样。确保在启动应用程序之前进行更改,并且它应该显示正确的格式。

要更改区域设置(在模拟器上):
启动模拟器(通过启动您的应用),按 Home 按钮,转到 SettingsGeneralInternational然后选择您要测试的区域格式。完成后关闭模拟器并重新启动您的应用程序。区域设置已更改,因此您应该在显示的货币符号中看到这一点。

在真实设备上,您可以按照相同的路线更改区域设置。

The simulator has support for changing localizations, just like on a regular device. Make sure that you change that before starting your app and it should show the correct format.

To change the locale (on the simulator):
Start the simulator (by starting your app), press the Home button, go to Settings, General, International and then choose the Region Format you want to test. Close the simulator after it's done and restart your app. The locale has changed so you should see that in the currency symbol that is shown.

On real devices you follow the same route to change the locale.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文