[erlang-questions] Stringified integer with leading zeroes
Dan Gudmundsson
dangud@REDACTED
Wed Jan 25 15:56:40 CET 2012
And the same with ~w
io:format("~10..0w~n", [123]).
/Dan
On Wed, Jan 25, 2012 at 3:39 PM, Masklinn <masklinn@REDACTED> wrote:
>
> On 2012-01-25, at 15:30 , Avinash Dhumane wrote:
>
>> How to get an integer 123 as 10-char long string "0000000123" with leading zeroes, i.e. erlang term [48, 48, 48, 48, 48, 48, 48, 49, 50, 51]?
>>
>> Following is not what I expect! I tried with both ~B and ~s.
>
> 5> io_lib:fwrite("~10..0B", [123]).
> [[[48,"000",48,48,48],49,50,51]]
> 6> lists:flatten(io_lib:fwrite("~10..0B", [123])).
> "0000000123"
>
> io_lib:fwrite returns an iolist. In fact you can pass it straight to io:format it's going to print the right thing:
>
> 10> io:format(io_lib:fwrite("~10..0B", [123])).
> 0000000123ok
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list