Search code examples
javalocaledollar-signjava-19

Currency difference between java 18 and java 19


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 ?


Solution

  • 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.