4

I am trying to migrate to java 19 from java 18. Here is the code I run:

NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(Locale.CANADA_FRENCH);
currencyFormatter.setMaximumFractionDigits(2);
currencyFormatter.setCurrency(Currency.getInstance(Locale.CANADA_FRENCH));
var result = currencyFormatter.format(100);
System.out.println(result);

It gives different results for those 2 java versions.

Java 18: 100,00 $ CA Java 19: 100,00 $

I cannot find any details in release notes regarding that change. Am I doing something wrong, or this is expected ?

  • 2
    Just for the records: the outcome is the same when you omit the redundant `currencyFormatter.setCurrency(Currency.getInstance(Locale.CANADA_FRENCH));`? – Holger Jan 09 '23 at 13:48
  • 1
    The outcome is the same, I mean there is the same difference – Jakub Bręk Jan 09 '23 at 13:52
  • 3
    Only JDK 16 to 18 produce the outcome `100,00 $ CA`. So the change with JDK 19 is a change back to a long standing behavior. – Holger Jan 09 '23 at 13:55
  • 4
    Generally speaking: localization data such as this is subject to change. Any release can pull in new data (usually from CLDR or other sources) that changes any specific detail. If your code (or UI) cares about using a *specific* currency sign for a given locale, it's better to explicitly set it than to depend on what the system provides you. – Joachim Sauer Jan 09 '23 at 14:40

1 Answers1

2

I cannot find any details in release notes regarding that change.

That's true. You will not find any because maintaining localization changes is not a responsibility of the JDK team. Each JDK release (since 9, see JEP-252) uses embeded data from The Unicode Common Locale Data Repository (CLDR) to produce given locale ouput. The CLDR has it's own independent maintainers and release cycle and its contnents may change inbetween JDK releases. That means you should be aware of potential changes in that matter without being notified by the JDK team. As Joachim Sauer mentioned in the comment (he was working on JDK and JEP-252 implementation), if your code relies on these changes you can always override the defaults and use custom formatting rules.

You can get more context about CLDR in What is Common Locale Data Repository (CLDR) - JDK 9.

Marcin Kłopotek
  • 5,271
  • 4
  • 31
  • 51
  • See also this related info from Oracle, which also shows how to revert to the previous behaviour: https://docs.oracle.com/javase/10/intl/internationalization-enhancements-jdk-9.htm – michid Jan 09 '23 at 16:22