[erlang-questions] io:format printing integers prefixed with zero(0)

Peter Lund <>
Mon May 5 11:17:11 CEST 2008


or:

1> string:right(integer_to_list(3),3,$0).
"003"
2> string:right(integer_to_list(50),3,$0).
"050"
3> string:right(integer_to_list(205),3,$0).
"205"
4> string:right(integer_to_list(33205),3,$0).
"205"

does almost the same...

Michael McDaniel skrev:
> On Sat, May 03, 2008 at 02:51:33PM +1000, jm wrote:
>   
>> Given an integer is there a format which will prefix it with zeros to a 
>>   fixed width? eg,
>>
>>    3 => 003
>>   50 => 050
>> 205 => 205
>>
>> the equivelant of C's printf("%3.3d", i).
>>
>>
>> Jeff.
>> _______________________________________________
>>     
>
>
>
> ()40> io:fwrite("~3.3.0w ", [1]).
> 001 ok
> ()41> io:fwrite("~3.3.0w ", [10]).
> 010 ok
> ()42> io:fwrite("~3.3.0w ", [100]).
> 100 ok
> ()43> 
>
>
>  see io docs; file:///usr/local/lib/erlang/lib/stdlib-1.15/doc/html/io.html
>  on my system
>
>
> ~Michael
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
>   




More information about the erlang-questions mailing list