Java Reference
In-Depth Information
Flag
x/X
Meaning
d
o
'+'
x
x
Always include the sign
(space) Include a leading
space for positive values
' '
x
x
Use zero-padding (else
spaces)
'0'
Include grouping separat-
ors
','
x
x
Enclose negative values in
parentheses
'('
x
x
For example, to print a zero-padded, hexadecimal value with a radix in-
dicator and a minimum width of 10, you could use
System.out.printf("%0#10x %n", val);
which for
val
equal to 32 prints
0x00000020
You cannot use
+
and space together, nor can you use and
0
together. If
either of
0
or is given then a width must be given.