formatting currency in java 17

855 Views Asked by At

There is no doubt that there is some piece of information I'm missing on this.

I've run the following code

import java.text.NumberFormat;
import java.util.Locale;
import java.math.BigDecimal;

class Main {
  public static void main(String[] args) {
    NumberFormat canadaFrench = NumberFormat.getCurrencyInstance(Locale.CANADA_FRENCH);
NumberFormat canadaEnglish = NumberFormat.getCurrencyInstance(Locale.CANADA);

BigDecimal amount = new BigDecimal("123456789.99");

System.out.println(canadaFrench.format(amount));
System.out.println(canadaEnglish.format(amount));
  }
}

In java pre-17 the result is as follow

123 456 789,99 $
$123,456,789.99

But from java 17

123 456 789,99 $ CA
$123,456,789.99

I went ahead and tested this into java 19. With that version the formatting is corrected.

Why is the formatting of french canadian changed ?

2

There are 2 best solutions below

0
On

the same issue shows up in another project, this time getting the java 21 fixed this issue

0
On

I ended up on this page https://bugs.openjdk.org/browse/JDK-8282929

Which point the issue, it's already fix in 19, and it was backported to other actively supported versions.

According to that page the fix is present in 17.0.4, but using 17.0.4.1 still show this defect