[erlang-questions] Formatting integers with io_lib

Bryan Robinson [ICG-MKTS] <>
Thu Oct 28 15:54:37 CEST 2010


Ulf,

Thank you, I plugged that in and it worked.

Mazen,

Thank you, that was the documentation I was looking at, but I missed the
"~F.P.PadModC" part.  When I opened your link there it was right before
me!  Thanks.

- Bryan

On 10/28/10 03:39, Mazen Harake wrote:
> Relevant documentation:
> http://www.erlang.org/doc/man/io.html#format-2
> 
> On 27/10/2010 21:41, Ulf Wiger wrote:
>> 1>  {H,M,S} = time().
>> {21,37,1}
>> 2>  io:fwrite("~2.2.0w.~2.2.0w.~2.2.0w~n",[H,M,S]).
>> 21.37.01
>>
>> BR,
>> Ulf W
>>
>> On 27 Oct 2010, at 21:32, Bryan Robinson [ICG-MKTS] wrote:
>>
>>> I may have missed or misunderstood something in the io_lib and io
>>> library documentation, but is there a way to use io_lib:format() to
>>> insert leading zero characters on small integers?  For example, in the
>>> Erlang shell:
>>>
>>> {_,Time} = calendar:local_time().
>>> {H,M,S} = Time.
>>> Msg = io_lib:format("~w:~w:~w", [H,M,S]").
>>> io_format("~s", Msg).
>>>
>>> I get "15:2:9".  I would like to get back "15:02:09", and of course when
>>> the integer is two digits I would not like the leading zero.
>>>
>>> Is there a similar way to do this like with the C stdlib and the %0n
>>> where n=2 formatter?
>>>
>>> printf("%02d:%02d:%02d", h, m, t);
>>>
>>> I would appreciate any pointers or tips.  Thank you!
>>>
>>> -- 
>>>
>>> - Bryan
>>>
>>> ________________________________________________________________
>>> erlang-questions (at) erlang.org mailing list.
>>> See http://www.erlang.org/faq.html
>>> To unsubscribe; mailto:
>>>
>> Ulf Wiger, CTO, Erlang Solutions, Ltd.
>> http://erlang-solutions.com
>>
>>
>>
>>
>> ________________________________________________________________
>> erlang-questions (at) erlang.org mailing list.
>> See http://www.erlang.org/faq.html
>> To unsubscribe; mailto:
>>
> 


-- 

//////////////////////////////////////
Bryan Robinson
Automated Trading Desk, A Citi Company
+1.843.789.2287


Automated Trading Desk, LLC (ATD) is the owner of Automated Trading Desk
Financial Services, LLC (AUTO) and Automated Trading Desk Brokerage
Services, LLC (ATDB), both FINRA members and Members SIPC. ATD does not
offer any brokerage services and is not a FINRA member. All brokerage
services, trading functions, execution of order flow and related matters
are performed through AUTO and ATDB utilizing ATD's proprietary
technology and software. Any reference to ATD trading, ATD trading
services, ATD trading performance, ATD orders, we, us, our or other such
usage refers to the services and trading activities of AUTO and ATDB
utilizing ATD's proprietary technology and software. Periods of market
volatility or other system delays may adversely affect trade execution
and related services.
//////////////////////////////////////


More information about the erlang-questions mailing list