I want to format a number by a given format string using DecimalFormat
. This is documented in the oracle java docs.
public class DecimalFormatDemo {
static public void customFormat(String pattern, double value ) {
DecimalFormat myFormatter = new DecimalFormat(pattern);
String output = myFormatter.format(value);
System.out.println(value + " " + pattern + " " + output);
}
static public void main(String[] args) {
customFormat("###,###.###", 123456.789);
}
}
But my output is German format style on my German os:
actual: 123456.789 ###,###.### 123.456,789
expected: 123456.789 ###,###.### 123,456.789
I know that I can explicitly set the separators. But I want to be able to set the format by a string like in the oracle docs. This should be independent of my os locale.