Scalabium Software

SMReport Autogenerated
Knowledge for your independence'.
Home Delphi and C++Builder tips

#132: I want to add leading zeros for numbers

Sometimes you need add the leading zeros to numbers for formatted printing of report forms or data exporting.

For this task I wrote a small function which return a formatted string (see below the AddLeadingZeros function).

But today I found that standard Format function allow to do a same!
Format('%.10d', [15]) will return '0000000015'

Don't ask me why in Delphi help you'll not find the description of this formatted string or why I didn't find it before:-(

Below is my old function:

function AddLeadingZeros(const Source: string; Len: Integer): string;
  i: Integer;
  Result := Source;
  for i := 1 to (Len-Length(Source)) do
    Result := '0' + Result;

Published: November 19, 2001

See also
ABA Document Convert
ABA Spreadsheet Convert
Database Information Manager
Clarion Viewer
ABA Database Convert
Word Web-stream
ABA Picture Convert
Metafile Convert
DBExport tools

Contact to webmaster


Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2018, Scalabium Software. All rights reserved.

SMExport advertising