如何将国家代码转换为对应的货币?
我需要根据用户在我的应用程序中将国家/地区代码转换为货币。
根据我的地理位置库,我知道用户是否位于美国(US)、德国(DE)、瑞士(CH)、日本(JPY)等。现在我需要从国家代码转换为相应的货币:
US -> USD ($)
DE -> EURO (€)
CH -> CHF (CHF)
JP -> YEN (JPY)
我怎样才能在Java中做到这一点?
I need to convert a country code to a currency in my app on a user basis.
Based on my geolocation library, I know whether the user is in the United States (US), Germany (DE), Switzerland (CH), Japan (JPY), etc. Now I need to convert from the country code to the corresponding currency:
US -> USD ($)
DE -> EURO (€)
CH -> CHF (CHF)
JP -> YEN (JPY)
How can I do this in Java?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的。标准 JDK 支持主要外币:
输出:
希望这有帮助。
Yes. The standard JDK supports major foreign currencies:
Outputs:
Hope this is helpful.
您应该解析此页面并将其存储在您的数据库中。
从互联网来源构建适合应用程序需求的良好数据库很困难,但这确实值得。要解析 html,我建议您尝试正则表达式,如果它变得太复杂,请使用 apache jericho 或 标签汤。
You should parse this page and store it in your database.
It's hard to build good databases suited to an apps need from Internet sources, but it's really worth it. To parse html, I suggest you try regexp, and if it gets too complicated, please use apache jericho or tag soup.
这又如何呢?这是一个黑客,但似乎工作正常。
给定 GB 的输出:
问题是货币可能会将名称显示为符号而不是符号($ £ 等)。货币必须在其原产国的区域设置下创建才能发挥作用。如果修复此问题,您的货币可能仍然带有看起来不正确的符号。
What about this? It's a hack but seems to work okay.
Output with GB given:
An issue is that a currency may display the name as symbol rather than the symbol ($ £ etc.). The currency has to be created with the locale of its originating country for that to work. If you fix this, you might still have currencies with symbols that don't look right.