Scalabium Software

SMExport advertising
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;
var
  i: Integer;
begin
  Result := Source;
  for i := 1 to (Len-Length(Source)) do
    Result := '0' + Result;
end;


Published: November 19, 2001

See also
 
Word Web-stream
SMDBGrid
Database Information Manager
DBISAM Viewer
Viewer for TNEF-files (winmail.dat)
Excel Reader (dll)
DBLoad
dBase Viewer
Paradox ActiveX
ExcelFile Viewer
 
 


Contact to webmaster

 

Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2025, Scalabium Software. All rights reserved.
webmaster@scalabium.com

SMExport advertising