Is there a nice printing API for a math string somewhere?
4 answers
You can do it with DecimalFormat :
NumberFormat f = NumberFormat.getInstance(loc);
if (f instanceof DecimalFormat) {
DecimalFormat df = (DecimalFormat) f;
df.setGroupingUsed(true);
df.setGroupingSize(3);
System.out.println(df.format(myNumber));
}
+3
a source to share
When it comes to formatting "," (I think you mean the thousands separator). NumberFormat is your friend. More specifically, I think you would like to use your own DecimalFormat subclass , which can format a number according to a given pattern.
0
a source to share
The "," part can be performed with the "," Formatter flag used, for example. String.Format. It was called the Grouping Separator .
0
a source to share