For the code below I get a different result when I run it like this, and when I run it inside a Tomcat web app.
public static void main(String[] args)
{
System.out.println(System.getProperty("user.language"));
System.out.println(System.getProperty("user.country"));
System.out.println(Locale.getDefault(Category.DISPLAY));
System.out.println(Locale.getDefault(Category.FORMAT));
Locale l = new Locale("de", "DE");
System.out.println(l.getDisplayLanguage());
DecimalFormatSymbols dfs = new DecimalFormatSymbols(l);
System.out.println(dfs.getDecimalSeparator());
l = new Locale.Builder().setLanguage("de").setRegion("DE").build();
System.out.println(l.getDisplayLanguage());
dfs = new DecimalFormatSymbols(l);
System.out.println(dfs.getDecimalSeparator());
}
Standalone result (expected):
en
US
en_US
en_US
German
,
German
,
In Tomcat:
en
US
en_US
en_US
German
.
German
.
Can someone suggest what else influences DecimalFormatSymbols (and NumberFormat for that matter) that it doesn't use the locale provided. I'm using JDK 1.8 with language level 1.7.
EDIT: This only happens when Tomcat runs in Eclipse. Eclipse/OSGi seems to interfere with the locale-based formatting, but only in a specific situation.
Just use %. 2f as the format specifier. This will make the Java printf format a double to two decimal places.
DecimalFormat isn't thread-safe, thus we should pay special attention when sharing the same instance between threads.
You can use the DecimalFormat class to format decimal numbers into locale-specific strings. This class allows you to control the display of leading and trailing zeros, prefixes and suffixes, grouping (thousands) separators, and the decimal separator.
Tomcat our ENV setting might have an issue i see it from the post here.
Try starting the tomcat as suggested in the above post with the following params set as a batch file:
-Duser.timezone=Europe/Berlin
-Duser.country=DE
-Duser.language=de
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With