Domanda

The following snippet behaves different in Java 6 than Java 7:

final Locale locale = new Locale("nb", "NO");
System.out.println(locale.getDisplayLanguage()); // Norwegian Bokmål

final DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale);
System.out.println(dfs.getDecimalSeparator());   // Java 6: .
                                                 // Java 7: ,

Why is that? Is this change documented somewhere?

È stato utile?

Soluzione 2

According to JDK 6 and JRE 6 Supported Locales and JDK 7 and JRE 7 Supported Locales, the correct/supported syntax for selecting Norwegian Bokmål is "no"/"NO".

new Locale("no", "NO") gives the correct result under both Java 6 and Java 7.

Altri suggerimenti

Java 6 had a number of issues regarding Locales, and this may well be one of them. Certainly, the correct separator for the Norway locale is ,.

The Oracle bug database does show quite a few bugs related to NO locale...

CLDR

In Java 9 and later, the OpenJDK-based implementations of Java switched to using locale data obtained from the Unicode Consortium’s Common Locale Data Repository (CLDR) (see Wikipedia) by default.

This switch provides much richer locale data than previously seen in Java. And this switch may mean that you see a change in behavior for some aspects of some locales.

See: JEP 252: Use CLDR Locale Data by Default

COMMA in Java 10

When I run this code:

    System.out.println( "java.version: " + System.getProperty( "java.version" ) );

    final Locale locale = new Locale( "nb" , "NO" );
    System.out.println( locale.getDisplayLanguage() ); // Norwegian Bokmål

    final DecimalFormatSymbols dfs = new DecimalFormatSymbols( locale );
    System.out.println( dfs.getDecimalSeparator() );

I get the COMMA character.

java.version: 10.0.2

Norwegian Bokmål

,

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top