Java:货币到区域设置映射可能吗? [英] Java: Currency to Locale Mapping Possible?
问题描述
正确的行为说的是在用户的首选语言环境中格式化数量,而不是货币的典型语言环境。在客户端,您将拥有用户的偏好(Locale.getDefault());如果您在Web服务器端进行了一些操作,请使用Accept-Language或者最好是页面内容的语言环境来获取适当的语言环境。
推理是这样的:
英美用户将理解10,000,000欧元15,但不适用于德国等值,10.000.000,15欧元。
包含足够的信息来推断一个合适的地区,无论如何。
I have a value stored in a DB correlating to a monetary amount, say 10.0. I also have access to the Currency/CurrencyCode. How can I use NumberFormat/DecimalFormat/(other?) to format when I don't know the Locale? According to the docs it will pick a default locale which won't work with a foreign Currency.
The correct behavior, generally speaking, is to format the amount in the User's preferred locale, not the currency's typical locale. On the client side, you'll have the user's preference (Locale.getDefault()); if you are doing something on the web server side, use the Accept-Language or, preferably, the page content's locale to obtain the proper a locale.
The reasoning is this: An English-US user will understand € 10,000,000.15 but not the suitable-for-Germany equivalent, € 10.000.000,15
The currency itself doesn't contain enough information to infer a suitable locale, anyway.
这篇关于Java:货币到区域设置映射可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!