Character Description Example
Pound sign (#) Modify selected numeric
conversions:- For %o, %x, or %X, print 0 ,
0x, or 0X prefix. - For %f, %e, or %E, print
decimal point even when
precision is 0. - For %g or %G, do not remove
trailing zeroes or decimal
point.
%#5.0fRight- and left-justify the output. The default behavior is to right-justify the output text.txt = sprintf('right-justify: %12.2f\nleft-justify: %-12.2f',...
12.3, 12.3)txt =
'right-justify: 12.30
left-justify: 12.30 'Display a + sign for positive numbers. The default behavior is to omit the leading + sign
for positive numbers.txt = sprintf('no sign: %12.2f\nsign: %+12.2f',...
12.3, 12.3)txt =
'no sign: 12.30
sign: +12.30'Pad to the left with spaces and zeroes. The default behavior is to pad with spaces.txt = sprintf('Pad with spaces: %12.2f\nPad with zeroes: %012.2f',...
5.2, 5.2)txt =
'Pad with spaces: 5.20
Pad with zeroes: 000000005.20'6 Characters and Strings