[fpc-pascal] Format(), leading zeros, and hex digits
    Michael Van Canneyt 
    michael at freepascal.org
       
    Sat Feb 22 13:53:21 CET 2014
    
    
  
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.
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.
>
> In a similar vein, am I correct in understanding that FPC's Format() doesn't 
> allow the case to be controlled in hex output? C's printf() distinguishes 
> between %x and %X for case control.
You are correct in your understanding.
Michael.
    
    
More information about the fpc-pascal
mailing list