Format directives in Erlang
~s, ~p, ~B, ~.2f: the io:format vocabulary.
%% io:format directives: ~s strings, ~p terms, ~B integers, ~.2f.
main(_) ->
Operator = "Maud",
Calls = 47,
Uptime = 99.9625,
io:format("~s connected ~B calls~n", [Operator, Calls]),
io:format("Uptime: ~.2f percent~n", [Uptime]),
%% ~p pretty-prints any term, quoting where needed.
io:format("Raw term: ~p~n", [{shift, night, [3, 7]}]),
%% io_lib:format builds the string instead of printing.
Label = io_lib:format("~s-~B", [Operator, Calls]),
io:format("Label: ~s~n", [Label]).
How it works
~Bprints integers;~.2ffixes float decimals.~ppretty-prints any term with quoting.io_lib:formatreturns the text instead of printing it.
Keywords and builtins used here
formatmain
The run, in numbers
- Lines
- 15
- Characters to type
- 481
- Tokens
- 119
- Three-star pace
- 60 tpm
At the three-star pace of 60 tokens a minute, this run takes about 119 seconds.
Step 2 of 4 in Text & numbers, step 20 of 31 in Language basics.