Practical technical guides / Java

The Default Locale Changes Java Output: Dotless i, Decimal Commas and Locale.ROOT

Measured on JDK 23: toLowerCase, String.format and NumberFormat change output under Turkish, German, French and Arabic locales. Use Locale.ROOT for machine output.

By Sandeep Belgavi · Published 2026-11-30

Measured on JDK 23: toLowerCase, String.format and NumberFormat change output under Turkish, German, French and Arabic locales. Use Locale.ROOT for machine output.

A bug that appears only on other machines

Java has many methods that quietly read the JVM's default locale: String.toLowerCase() and toUpperCase() with no argument, String.format, NumberFormat.getInstance(), DateTimeFormatter.ofPattern without a locale, and more. On a developer machine set to US English, all of them produce the output the developer expects. On a server whose locale is Turkish, German or Arabic, the same code produces different strings, and a file, a cache key or a query built from them breaks.

The default locale comes from the operating system unless the JVM is told otherwise. It changes with the server image, a container's environment, a CI runner or a colleague's laptop. That is why these bugs are found late: they depend on where the code runs, not on what it does.

This guide measures the common traps on JDK 23, explains what each one does, and shows the fix: pass Locale.ROOT or an explicit format wherever the output is meant for a machine. The companion example java_locale_traps prints every value below and checks the fixes.

Measured on JDK 23

The probe sets the default locale with Locale.setDefault and prints the same expressions in six locales. Values come from a Belgavi's Book Store export: a column key, an ISBN label, a price of 1234.5, a count of 1234567 and the string "12.50" parsed as a number. It ran on JDK 23.0.2 on Windows 11.

Default locale"TITLE".toLowerCase()"isbn".toUpperCase()String.format("%.2f", 1234.5)String.format("%,d", 1234567)NumberFormat.getInstance().parse("12.50")
en-UStitleISBN1234.501,234,56712.5
tr-TRtıtleİSBN1234,501.234.5671250
de-DEtitleISBN1234,501.234.5671250
fr-FRtitleISBN1234,501 234 56712
hi-INtitleISBN1234.501,234,56712.5
ar-EGtitleISBN١٢٣٤٫٥٠١٬٢٣٤٬٥٦٧12

Each column is its own bug.

Case mapping: the Turkish i

Turkish has two letters i: dotted (i, İ) and dotless (ı, I). In the Turkish locale, the lowercase of I is ı (U+0131) and the uppercase of i is İ (U+0130). The String.toLowerCase() documentation calls this out: locale-sensitive results, with the Turkish example, and it recommends toLowerCase(Locale.ROOT) for locale-insensitive strings such as protocol keys and HTML tags.

In the measurement, "TITLE".toLowerCase() produced tıtle under tr-TR, and "isbn".toUpperCase() produced İSBN. Neither equals the expected string. Code that normalises a header name, a JSON key, an enum name or a configuration key this way stops matching, and the failure usually looks like a missing key, not a locale problem. A classic case is Enum.valueOf(name.toUpperCase()): on a Turkish JVM, an enum constant whose name contains I can no longer be found.

Formatting: decimal and grouping separators

String.format uses the default locale for format specifiers. %.2f of 1234.5 printed 1234,50 in Turkish, German and French, with a comma as the decimal separator, and Arabic-Indic digits (١٢٣٤٫٥٠) in Egyptian Arabic. %,d used a period, a narrow no-break space (U+202F) or an Arabic thousands separator depending on the locale.

That is correct behaviour for text shown to a person. It is wrong for anything another program reads: a CSV file, a SQL literal, a JSON value written by hand, a log field parsed by a dashboard, a cache key. A CSV written with String.format("%.2f", price) on a German server puts commas inside numbers, and the column split changes.

One measured detail is reassuring: string concatenation and Double.toString are not locale-sensitive. "price > " + 12.5 printed price > 12.5 in every locale. The trap is specifically the formatting APIs.

Parsing: the most dangerous direction

NumberFormat.getInstance().parse("12.50") returned 12.5 in English, 1250 in Turkish and German, where the period is a grouping separator, and 12 in French and Arabic, where parsing stops at the first character it does not accept. None of these throws. A price of 12.50 read from a file becomes 1250 or 12 without an error. Parsing is worse than formatting because the wrong value enters the system silently and looks plausible.

The fixes

String key = header.toLowerCase(Locale.ROOT);
String label = name.toUpperCase(Locale.ROOT);
String csvPrice = String.format(Locale.ROOT, "%.2f", price);
BigDecimal parsed = new BigDecimal("12.50");             // locale-independent grammar
String plain = new BigDecimal("1234.50").toPlainString(); // for machine output
DateTimeFormatter iso = DateTimeFormatter.ISO_LOCAL_DATE;  // already locale-independent

With these forms, the fixed line the example prints is identical in all six locales: key=title|upper=ISBN|price=1234.50|plain=1234.50|parse=12.50|date=2026-10-05, and the check mode confirms it. Locale.ROOT is the neutral locale, intended for exactly this purpose. Some code uses Locale.US or Locale.ENGLISH instead; they also work for these cases, but ROOT states the intent, which is "no locale", rather than picking a country.

For display, use the user's locale explicitly, passed in from the request or the user's profile, rather than the JVM default. The default is the locale of the server, which is rarely the reader's.

Dates follow the same rule

DateTimeFormatter.ofPattern("dd MMM yyyy") without a locale uses the default locale too, so month and day names change language. Measured on JDK 23.0.2: 5 October 2026 formats as 05 Oct 2026 in en-US, 05 Okt. 2026 in de-DE and 05 Eki 2026 in tr-TR, and parsing the string 05 Oct 2026 throws DateTimeParseException under de-DE and tr-TR. The same pattern with Locale.ROOT parses it in every locale. The predefined ISO formatters, such as DateTimeFormatter.ISO_LOCAL_DATE and ISO_INSTANT, do not depend on the locale, which is why they are the right choice for files, APIs and logs. If a pattern is unavoidable for machine output, pass Locale.ROOT with ofPattern(pattern, Locale.ROOT), and keep month names out of machine formats entirely.

Pinning the default, and why it is not enough

You can pin the JVM's default with -Duser.language=en -Duser.country=US or by setting Locale.setDefault at startup, and container images often set LANG=C.UTF-8. This reduces surprises, and it is worth doing so that logs and errors are consistent. It is not a fix. Libraries and tests run in other processes, and the next service that reuses the code may not pin anything. The robust fix is the explicit locale at each call that produces machine-readable output.

Finding the call sites

  • Search for the no-argument forms: toLowerCase(), toUpperCase(), String.format( without a Locale first argument, NumberFormat.getInstance(), DecimalFormat constructed without symbols, DateTimeFormatter.ofPattern( without a locale, and Scanner reading numbers.
  • Static analysis catches many of them; several Java linters flag case conversion and formatting that rely on the default locale.
  • Run the test suite once with a hostile default, for example -Duser.language=tr -Duser.country=TR, and once with de-DE. Failures point directly at locale-sensitive code. This is cheap enough to add as a CI job.

Failure modes

  • Fixing formatting but not parsing. Code that writes 1234.50 with Locale.ROOT and reads it back with the default NumberFormat still breaks on a German server.
  • Locale-sensitive comparisons. equalsIgnoreCase is not affected by the default locale, but toLowerCase().equals(...) is. Prefer equalsIgnoreCase or explicit ROOT lowering.
  • Generated SQL. A query built with String.format("... price > %.2f", x) on a German server produces price > 12,50, which is a syntax error or, worse, a comparison with two values. Use bind parameters, which avoid formatting entirely.
  • Fonts and digits in reports. Arabic-Indic digits in a log that a dashboard parses will not match a numeric regex. Machine-facing fields should be ASCII.

Verification

Run java src/LocaleTraps.java from the companion example to print the table for your JDK, and java src/LocaleTraps.java --check, which exits with status 1 if any of the fixed expressions differs between locales. The recorded output from JDK 23.0.2 is in expected-jdk23-windows.txt. Locale data can differ between JDK versions, since the JDK uses CLDR data that is updated over time, so expect small differences in grouping characters on other versions; the traps themselves do not change.

Primary references and authorship

Sources checked 2026-11-30. Original explanation and synthetic examples by Sandeep Belgavi. Companion code: Sandeep-BA/agent-decision-lab/examples/java/java_locale_traps. Views are my own and do not represent any employer, past or present.