views:

164

answers:

2

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?

+12  A: 

io:format("~4..0B~n", [Num]).

Zed
+2  A: 

string:right(integer_to_list(4), 4, $0).

Tim Fletcher