[fpc-pascal] Format(), leading zeros, and hex digits
Mark Morgan Lloyd
markMLl.fpc-pascal at telemetry.co.uk
Sat Feb 22 15:11:11 CET 2014
Michael Van Canneyt wrote:
> On Sat, 22 Feb 2014, Mark Morgan Lloyd wrote:
>
>> Is it possible to get Format() to pad with leading zeros rather than
>> spaces, particularly in the case of hex numbers? My understanding is
>> that printf() interprets e.g. %02s as being padded with zeros.
>
> For string arguments, this is not possible.
My mistake, I meant %02x.
> You can use %.2d for this, or %.2x for hex numbers:
>
> araminta: >./tf
> 000F
> araminta: >cat tf.pp
> uses sysutils;
>
> begin
> writeln(format('%.4x',[15]));
> end.
Thanks, I now see that is described in the example at
http://lazarus-ccr.sourceforge.net/docs/rtl/sysutils/format.html but not
in the preceding formal documentation.
Reminder noted with thanks.
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
More information about the fpc-pascal
mailing list