I need to pad the output of an integer to a given length.
For example, with a length of 4 digits, the output of the integer 4 is "0004" instead of "4". How can I do this in Erlang?
adding a bit of explanation to Zed's answer:
Erlang Format specification is: ~F.P.PadModC.
"~4..0B~n" translates to:
"~4..0B~n"
~F. = ~4. (Field width of 4) P. = . (no Precision specified) Pad = 0 (Pad with zeroes) Mod = (no control sequence Modifier specified) C = B (Control sequence B = integer in default base 10)
and ~n is new line.
~n
2.1m questions
2.1m answers
60 comments
57.0k users