DecimalFormat numform = new DecimalFormat("000,000.00"); 
System.out.println( "Num = " + numform.format(98765.432) );

Answer:

Num = 098,765.43

Thousands Separators

The format pattern to the left of the decimal separator can include commas to show thousands-separators. Even in locales where comma is not the proper thousands separator, the format string uses comma. The output string will use the correct separator for the default locale. (There are methods that change this behavior, not covered here.)

There must be no thousands-separators in the characters on the right of the decimal point.

Here is the applet again. Play a bit with patterns that include thousands-separators.

Try putting thousands separators on the right of the decimal point. The program will throw an exception. (The applet writes an error message when this happens.)

QUESTION 11:

Try a format pattern like 0,0,0,0.0 where groups of digits other than three are separated. Does this work?