DecimalFormat: applyPattern(String pattern)
import java.text.DecimalFormat;
import java.text.NumberFormat;
public class MainClass {
public static void main(String[] argv) {
double d = 1234567.89;
double n = -1234567.89;
String pattern = "#,###.##;(#,###.##)";
NumberFormat nf = NumberFormat.getInstance();
if (nf instanceof DecimalFormat) {
DecimalFormat df = (DecimalFormat) nf;
df.applyPattern(pattern);
System.out.println(df.format(d));
System.out.println(df.format(n));
}
}
}
Related examples in the same category