如果您有 ISO 国家代码 `US`、`FR`,如何获得区域设置代码(`Locale.US`、`Locale.FRANC

2024-08-25Java开发问题
20

本文介绍了如果您有 ISO 国家代码 `US`、`FR`,如何获得区域设置代码(`Locale.US`、`Locale.FRANCE`)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

如果你有国家代码USFR(ISO-3166-1 alpha-2国家代码),你如何获得Locale代码(Locale.US, Locale.FRANCE) 来做这样的事情:

If you have the country code US, FR (ISO-3166-1 alpha-2 country code), how do you get the Locale code (Locale.US, Locale.FRANCE) to do something like this:

System.out.println(DecimalFormat.getCurrencyInstance(Locale.US).format(12.34));
System.out.println(DecimalFormat.getCurrencyInstance(Locale.FRANCE).format(12.34));

$12.34
12,34 

推荐答案

你不能,因为 Locale 用于保存一种语言,而不是一个国家.它可以包含特定国家的语言,以及该国家的特定变体,但它首先是一种语言.语言和国家之间没有一对一的关系.大多数语言在不同的国家/地区使用,许多国家/地区有多种语言.

You can't, because a Locale is used to hold a language, not a country. It can hold a language for a specific country, and for a specific variant in this country, but it's a language first. And there is no one-to-one relationship between a language and a country. Most languages are spoken in various countries, and many countries have several languages.

如果您有一种语言的国家/地区代码,则可以使用 new Locale(code).但是有了国家代码,你所能做的就是调用getAvailableLocales,循环遍历结果,找到一个有你国家代码的.但可能有几个.

If you had the country code for a language, you could use new Locale(code). But with a country code, all you can do is call getAvailableLocales, loop through the results, and find one which has your country code. But there might be several ones.

这篇关于如果您有 ISO 国家代码 `US`、`FR`,如何获得区域设置代码(`Locale.US`、`Locale.FRANCE`)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

如何使用 JAVA 向 COM PORT 发送数据?
How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)...
2024-08-25 Java开发问题
21

如何使报表页面方向更改为“rtl"?
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)...
2024-08-25 Java开发问题
19

在 Eclipse 项目中使用西里尔文 .properties 文件
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)...
2024-08-25 Java开发问题
18

有没有办法在 Java 中检测 RTL 语言?
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)...
2024-08-25 Java开发问题
11

如何在 Java 中从 DB 加载资源包消息?
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)...
2024-08-25 Java开发问题
13

如何更改 Java 中的默认语言环境设置以使其保持一致?
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)...
2024-08-25 Java开发问题
13