igce
igce

Reputation: 11

NumberFormating issue with negative numbers in RTL Locale like Arabic

Locale locale = new Locale("ar", "AE");
NumberFormat format = NumberFormat.getNumberInstance(locale);                
System.out.println(format.parse("55-"));

The above code returns -55 with JDK 8 and returns 55 with 11. Also format.parse("-55") throws parseException. Any idea why is this change? How to parse negative numbers in Arabic (RTL) with java 11?

Upvotes: 1

Views: 350

Answers (1)

Enwired
Enwired

Reputation: 1593

Starting with Java 9, the JDK gives priority to CLDR locale data. (Unicode Common Locale Data Repository)

If you want to get the behavior seen in Java 8, you can use command-line parameter -Djava.locale.providers=COMPAT,SPI,CLDR

With this, it will use the older "COMPAT" locale data and only use SPI or CLDR if COMPAT doesn't have locale data for your locale.

https://www.oracle.com/java/technologies/javase/9-relnotes.html#JDK-8008577

This same java change also affects parsing negative numbers in Sweden, first day of the week in Germany, and probably many other things.

Upvotes: 0

Related Questions