This takes the form:
Format (const Format: string; const Args: array of const): string;
The function returns a formatted string. The string is formatted according to the arguments in the Args variant open array. The Format string is copied to the result string, expanding format specifiers, which start with a % sign (to get a literal per cent sign repeat it (%%).
% [index:] [-] width [.precision] type
Items in square brackets are optional.
%d
Format decimal integer; precision specifies minimum digits to display.
Examples:
format('%d',[5]); (displays 5)
format('There are now %d records in the table', [Count]); (displays the value of %d (=Count) in the correct place)
%e
Format floating point; precision specifies number of digits in string.
Examples:
format('%5e',[2.345]); (displays 2.345000000000000E+000)
%f
Format floating point with fixed point; precision specifies number of digits after decimal separator (for currency).
Examples:
format('%8.2f', [123.456]); (displays 123.46 - 2 decimal places, rounded to .46)
%g
Format floating point in general format; precision specifies number of significant digits;
format('%8.2g', [123.456]); (displays 1.2E2 - 2 significant figures specified)
%m
Format currency; precision specifies number of places after decimal point (in CurrencyDecimals); currency format given by CurrencyFormat and NegCurrFormat variables;
format('%8.2f', [123.456]); (displays £123.46 - 2 decimal places, rounded to .46, with £ symbol)
%n
Format floating point number using fixed notation with ThousandSeparator;
format('%8.2n', [1234.456]); (displays 1,234.46 - 2 decimal places, rounded to .46, comma separator)
%p
Format pointer as hex number;
%s
Format string - precision gives number of characters to display. Args value must be ANSIChar, ANSIstring, PChar, PWideChar, ShortString, Variant or WideString;
Examples:
format('%20s',['Hello world'])
Two parts of a line of text are displayed with left and right justification:
line:=format('%-20s',[first_string]) + ': '+ format('%30s',[second_string]);
Memo1.lines.Add(line);
%u
Format unsigned decimal integer;
Examples:
format('%u', [1024]); (displays 1024); format('%u', [-1024]); (displays 4294966272 - handles only unsigned numbers)
%x
Format unsigned hexadecimal number.
Examples:
format('%x', [1024]); (displays 400 (1024 in hex.)
Variable holding default number of decimal places in currency, taken from Windows locale (e.g. 2 for £ sterling).
Variable holding format. Four possible values: 0 (£1); 1 (1£); 2 (£ 1); 3 (1 £).
Defines the currency format used in floating-point to decimal conversions of negative numbers. 16 possible values (0-15); look them up in Help.
Defines the currency symbol (or characters) used in floating-point to decimal conversions. The initial value is fetched from LOCALE_SCURRENCY.
Defines character used as separator for decimal part of a number. Initial value fetched from LOCALE_STHOUSAND but can be replaced by e.g. ThousandSeparator:='/'.
Defines character used as separator for thousands. Initial value fetched from LOCALE_SDECIMAL but can be replaced by e.g. DecimalSeparator:='/'.