假设您要将用户首选项的区域设置存储在数据库中,您将使用哪个值?
en_US或en-US
它们是两个标准,但您更喜欢将哪一个用作自己应用程序的一部分?
更新:似乎许多网站使用破折号而不是下划线,例如
http://zh.wikipedia.org/zh-tw http://www.google.com.hk/search?hl=zh-TW
我正在使用 Locale(languageCode, countryCode) 构造函数将 BigDecimal 货币值转换为特定于语言环境的货币格式,如下面的代码所示
public static String formatCurrency(BigDecimal amount, String languageCode, String countryCode) {
Format format = NumberFormat.getCurrencyInstance(new Locale(languageCode, countryCode));
String formattedAmount = format.format(amount);
logger.debug("Orginal Amount {} and Formatted Amount {}", amount, formattedAmount);
return formattedAmount;
}
Run Code Online (Sandbox Code Playgroud)
现在根据Oracle Docs 上的优秀资源
运行时环境不要求每个区域设置敏感类都平等地支持所有区域设置。每个对语言环境敏感的类都实现自己对一组语言环境的支持,并且该集合可以因类而异。例如,数字格式类可以支持与日期格式类不同的一组语言环境。
由于我的 languageCode 和 countryCode 是由用户输入的,当用户输入错误的输入时,我如何处理这种情况(或者说 NumberFormat.getCurrencyInstance 方法如何处理它),比如 languageCode = de 和 countryCode = US。
它是否默认为某些 Locale ?这种情况如何处理。
谢谢。