Java String.format() Behaves Differently Under German Locale Settings
A developer found that String.format("%.2f", 0.5) produces "0,50" on a laptop with German regional settings, which then causes Double.parseDouble to throw a NumberFormatException. The article explains that string formatting in Java builds text from templates whose format specifiers such as %d, %s and %.2f are replaced by argument values. It compares the methods that produce this output, including String.format(), String.formatted() added in Java 15, System.out.printf() and the Formatter class. It also notes that all of these share the same template syntax and that locale settings such as German or French change the decimal separator from a point to a comma.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in