gpt4 book ai didi

java - 安卓货币符号排序

转载 作者:太空宇宙 更新时间:2023-11-03 10:26:01 25 4
gpt4 key购买 nike

我正在使用非英语语言环境的设备,英语货币的格式如下:

1 $

如果我有英语语言环境,我会得到欧元货币,例如:

1 欧元

使用

format.setCurrency(Currency.getInstance(currency));
return format.format(amount);

在文档中找到:

http://developer.android.com/reference/java/util/Currency.html#getSymbol ()

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$".

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.

If there is no locale-specific currency symbol, the ISO 4217 currency code is returned.

不是同一种方法,但可能相关。为什么以货币排序的符号会影响我设备的区域设置?无论我使用哪种语言环境,1$ 都是不正确的。

有办法改变吗?

最佳答案

该方法的行为是正确的。

并非所有国家/地区都希望货币符号位于金额之前。

如果您始终希望货币格式符合美国化的期望,请将区域设置保留为 Locale.US。如果您希望货币以本地化方式显示,请保持原样。

请参阅这份简短指南(来自 Microsoft,不少于此):

Currency Formatting

我猜您可能想要实现的目标是以适合其区域设置的格式显示货币?如果是这种情况,只需将区域设置与您使用的货币相匹配,然后再调用该方法。

请注意,格式在同一国家/地区甚至可能有所不同。在加拿大,说英语的人使用 $50.00 的格式相当普遍,而法裔加拿大人可能使用 50,00 $。

另见关于 UX 的这个问题:

https://ux.stackexchange.com/questions/22574/where-to-place-currency-symbol-when-localizing-and-what-to-do-with-odd-symbols

关于java - 安卓货币符号排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12490793/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com