Declared in two overloads as
The second version uses the TFormatSettings type variable which refers to localization information contained in the FormatSettings parameter.
function Format(const Format: string; const Args: array of const): string; overload; function Format(const Format: string; const Args: array of const; const FormatSettings: TFormatSettings): string; overload;
To display a number, you can use the next code:
Note the usage of the percentage character. The "%.2f" is the format string to be used when formatting the value "3/7" and converting to a string.
var s : string; begin s := Format('3 divided with 7 (using 2 decimal places) is %.2f',[3/7]) ; ShowMessage(s) ;
Displaying the Percentage Sign (%)A beginner Delphi developer might have problems with a line like:
The last percentage sign will NOT be a part of the resulting string.
Format('In percentage the value is %.2f %',[3/7]) ;
To fix this "problem" you simply need to use two % characters, as in
What's more, if you forget about the need to use the two % characters to make the Format function display the percentage sign, aline like this one will result in the "Format '% ' invalid or incompatible with argument".
Format('In percentage the value is %.2f %%',[3/7]) ;
To fix this, simply use two % characters, as in:
Format('3 % of 7 is %.2f',[3/7]) ;
Format('3 %% of 7 is %.2f',[3/7]) ;