0
我想使用DecimalFormat
以给定的格式字符串格式化数字。这在oracle java docs中有记录。DecimalFormat忽略给定的模式,但使用语言环境
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);
}
}
但我的输出是对我的德国德国OS格式式样:
actual: 123456.789 ###,###.### 123.456,789
expected: 123456.789 ###,###.### 123,456.789
我知道我能explicitly set the separators。 但我希望能够像Oracle文档中的字符串一样设置格式。这应该独立于我的OS语言环境。