Format Specifier Examples

The underline character (_) represent spaces in the output. The last three entries are examples of physical quantity inputs. The last table entry shows the output when the unit in the format specifier is in conflict with the input unit.

format string argument(s) resulting string
score= %2d%% 87 score= 87%
level= \n%7.2e V 0.03642 level= 3.64e2 V
Name: %s, %s. Smith John Name: Smith, John.
Temp: %05.1f %s 96.793 Fahrenheit Temp: 096.8 Fahrenheit
String: %10.5s. Hello, World String:_____Hello.
%5.3f 5.67 N 5.670 N
%5.3{mN}f 5.67 N 5670.000 mN
%5.3{kg}f 5.67 N 5.670 ?kg