Skip to content
Advertisement

Discrepancies between Java 11 and Java 8 DecimalFormat behaviour

I’ve got a weird issue with Java 11. I’m porting a huge project, and I have some tests which use DecimalFormat failing on the 11 build, but not on the 8 build.

DecimalFormat in Java 11 gives me a comma decimal separator, and on Java 8 it gives me a dot.

Here is a minimal reproducible example:

JavaScript

which outputs 1.02 on Java 8, and 1,02 on Java 11.

Here is the entire terminal session of building and running the example with both versions:

JavaScript

Has anyone had similar issues? Were there any changes to relevant classes between 8 and 11 which would cause this?

Advertisement

Answer

Yes, one of the changes was updating Locale Data to Unicode CLDR v33 (see https://www.oracle.com/java/technologies/javase/jdk-11-relnote.html)

This change is relevant for locale-specific formatting, which impacts the usage of the utils like DecimalFormat or SimpleDateFormat.

So if your code depends on locale-specific formatting, you should double check it after switching to Java 11.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement