Java 8 does not display currency symbol

I found one strange situation in Java 8. I am going to format the number to a specific locale, and some of them work incorrectly.

long tenMillion = 10000000L; // this is ten million
Locale[] locales = Locale.getAvailableLocales();
//Locale[] locales = NumberFormat.getAvailableLocales(); // the same situation
for (Locale locale : locales) {
String currency = "Ten million in " + locale.getDisplayName() + "  is " +
                NumberFormat.getCurrencyInstance(locale).format(tenMillion);
    if (locale.getDisplayName().equals("Ukrainian")){
        System.out.println(currency);
        System.out.println(Currency.getInstance("UAH").getSymbol(locale));
    }
}

Exit

Ten million in Ukrainian  is ¤ 10 000 000,00
UAH

But when I create an instance of this location, I have the correct results:

Locale uaLoc = new Locale("uk", "UA");
String currency = "Ten million in " + uaLoc.getDisplayName() + "  is " +
        NumberFormat.getCurrencyInstance(uaLoc).format(tenMillion);
System.out.println(currency);
System.out.println(Currency.getInstance("UAH").getSymbol(uaLoc));

Exit

Ten million in Ukrainian (Ukraine)  is 10 000 000 .
.

This is true not only for the Ukrainian language and for others:

Ten million in Bulgarian  is ¤ 10 000 000,00
Ten million in Italian  is ¤ 10.000.000,00
Ten million in Korean  is ¤ 10,000,000.00
Ten million in Latvian  is ¤ 10 000 000,00
etc.

But locales with countries are formatted correctly:

Ten million in Bulgarian (Bulgaria)  is .10 000 000
Ten million in Italian (Italy)  is10.000.000,00
Ten million in Italian (Switzerland)  is SFr. 10'000'000.00
Ten million in Korean (South Korea)  is10,000,000
Ten million in Latvian (Latvia)  is 10 000 000

It seems that the currency is only associated with the country. And this is a very correct way!

Does anyone know how to request API changes for Java 9? It would be great to follow the API

Locale.getAvailableCountryLocales(); 

to avoid misunderstandings.

thanks

+4
source share
3 answers

: : http://openjdk.java.net/jeps/1 ( ), , , . ( , " ".

, JCP Public, , JCP, Java Specification Agreement ( : . JSPA-pdf URL-).

: https://jcp.org/en/participation/overview

+1

. java 8

filter(List<LanguageRange> priorityList,Collection<Locale> locales)

RFC 4647

List<Locale.LanguageRange> list1 = new ArrayList<>();
list1.add(new Locale.LanguageRange("*-*"));
// Locales
List<Locale> list3 = Locale.filter(list1,Arrays.asList(Locale.getAvailableLocales()));
list3.forEach(System.out::println);

:

ar_AE
ar_JO
ar_SY
hr_HR
fr_BE
es_PA
mt_MT
es_VE
zh_TW
da_DK
es_PR
vi_VN
en_US
etc.

, -.

+1

Locale.getAvailableLocales() ,

  • ,
  • .

:

it, : Italian
it, CH: Italian (Switzerland)
it, IT: Italian (Italy)

ucrainian , Locale("uk"), - Locale("uk", "UA").

, , , + .

 if (locale.getDisplayName().startsWith("Ukrainian")){

ucrainian , , .

0

Source: https://habr.com/ru/post/1617730/


All Articles