I have a program that does algorithmic calculations with some number-output. I want this output to look nice and the program still being fast. I used the DecumalFormat but this makes it so slow, but works. Is there a way to set the default n开发者_运维知识库umber output so I wouldnt need DecimalFormat???
Locale deLocale = new Locale("de_DE");
// should be format: ###,###.### 123.456,789 de_DE
Locale.setDefault (deLocale);
double f=-123456.123458998;
System.out.println (""+f+""); // I wourld expect -123.456,123
// but the output is -123456.123458998
any ideas?? thanks! chris
You need to look at the Customizing Format.
You need a ###,###.### - de_DE
pattern.
String pattern= "###,###.###";
DecimalFormat myFormatter = new DecimalFormat(pattern);
double f=-123456.123458998;
String output = myFormatter.format(f);
System.out.println(f+ " " + pattern + " " + output);
EDIT : Use Predefined format, in case you don't want your own pattern.
精彩评论