Android货币符号排序 [英] Android currency symbol ordering
问题描述
我正在使用不符合英语语言环境的设备,英语货币的格式如下:
I'm getting on devices with not-english locale, the english currencies formated like this:
1美元
如果我使用英语语言环境,则会得到欧元货币,例如:
If I have english locale I get euro currency like:
€1
使用
format.setCurrency(Currency.getInstance(currency));
return format.format(amount);
在文档中找到:
http://developer.android.com/reference/java/util/Currency.html#getSymbol ()
在语言环境中返回此货币的本地化货币符号.也就是说,在给定"USD"和Locale.US的情况下,您将获得"$",但在给定"USD"和一个非美国语言环境的情况下,您将获得"US $".
Returns the localized currency symbol for this currency in locale. That is, given "USD" and Locale.US, you'd get "$", but given "USD" and a non-US locale, you'd get "US$".
如果语言环境仅指定语言而不是语言和国家/地区(例如Locale.JAPANESE或{new Locale("en",")}),而不是Locale.JAPAN或{new Locale("en"), "US")}),则返回ISO 4217货币代码.
If the locale only specifies a language rather than a language and a country (such as Locale.JAPANESE or {new Locale("en", "")} rather than Locale.JAPAN or {new Locale("en", "US")}), the ISO 4217 currency code is returned.
如果没有特定于语言环境的货币符号,则返回ISO 4217货币代码.
If there is no locale-specific currency symbol, the ISO 4217 currency code is returned.
方法不同,但可能相关.为什么在使用货币进行符号订购时,我的设备的语言环境会有所不同?不管我使用哪个语言环境,1 $都是错误的.
Is not the same method but probably related. Why does it make difference the locale of my device for the symbol ordering in the currency? 1$ is incorrect no matter which locale I'm using.
有没有办法改变这一点?
Is there a way to change this?
推荐答案
该方法的行为正确.
并非所有国家/地区都希望货币符号位于金额之前.
Not all countries expect the currency symbol before the amount.
如果您始终希望货币格式与美国化的期望相匹配,请将区域设置保留为Locale.US
.如果您希望货币以本地化方式显示,请保持实施不变.
If you always want the currency format to match an Americanised expectation, leave the locale as Locale.US
. If you want the currency to display in a localised way, leave your implementation as is.
请参阅此简要指南(不少于Microsoft):
See this brief guide (from Microsoft, no less):
我猜您可能想实现的目的是以适合其语言环境的格式显示货币?如果是这种情况,只需在调用方法之前将语言环境与您使用的货币匹配即可.
I'd guess what you may be trying to achieve is to display the currency in a format appropriate to its locale? If that's the case, just match the locale to the currency you're using, before calling the method.
请注意,同一国家/地区的格式甚至可能有所不同.在加拿大,通常会说英语的人使用$ 50.00的格式,而使用法语的加拿大人可能使用$ 50,00的格式.
Note that the format can even vary in the same country. In Canada, it's reasonably common to see English speakers use the format $50.00, whereas French-Canadians may use 50,00 $.
也可以在UX上看到此问题:
Also see this question on UX:
这篇关于Android货币符号排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!