Yes. However, the size of the groups should all be the same.
When a number is negative, a minus sign is output in front of all the characters called for by the format pattern. If there are spaces on the left of the format pattern, they will be output, with the minus sign to the left of them. This is usually an error. See the last example.
value of double | format pattern | output string |
---|---|---|
-123.456 | "000.000" | "-123.456" |
-123.456 | "000.0" | "-123.5" |
-89.008 | "0.00" | "-89.01" |
-89.008 | "0." | "-89." |
-1.1 | "0000.0000" | -0001.1000" |
-89.008 | " 0.0" | "- 89.0" |
The minus sign does not replace the leading zero. Here is the applet (yet again) for you to play with:
What does the following fragment write?
DecimalFormat numform = new DecimalFormat("-0.00"); System.out.println( "Num = " + numform.format(-924.56) );