SmartPascal
FormatCurr
Function
Rich formatting of a currency value into a string SysUtils unit
1  function FormatCurr ( const Formatting : string; Value : Currency ) : string;
2  function FormatCurr ( const Formatting : string; Value : Currency; FormatSettings : TFormatSettings ) : string;
Description
The FormatCurr function provides rich Formatting of a currency Value into a string.
 
The Formatting string may contain a mix of freeform text and control characters:
 
  : Forces digit display or 0
: Optional digit display
: Forces display of thousands
: Forces display of decimals
E+  : Forces signed exponent display
E-  : Optional sign exponent display
: Separator of +ve -ve and zero values

 
These are best understood by looking at the sample code.
 
Version 2 of this function is for use within threads. You furnish the FormatSettings record before invoking the call. It takes a local copy of global formatting variables that make the routine thread safe.
Related commands
CurrToStrF Convert a currency value to a string with formatting
Format Rich formatting of numbers and text into a string
FormatDateTime Rich formatting of a TDateTime variable into a string
FormatFloat Rich formatting of a floating point number into a string
StrToCurr Convert a number string into a currency value
 
Example code : Showing all of the formatting data types
var
  curr : Currency;

begin
  // Set up our floating point number
  curr := 1234.567;

  // Display a sample value using all of the format options

  // Round out the decimal value
  ShowMessage('##### : '+FormatCurr('#####', curr));
  ShowMessage('00000 : '+FormatCurr('00000', curr));
  ShowMessage('0     : '+FormatCurr('0'    , curr));
  ShowMessage('#,##0 : '+FormatCurr('#,##0', curr));
  ShowMessage(',0    : '+FormatCurr(',0'   , curr));
  ShowMessage('');

  // Include the decimal value
  ShowMessage('0.#### : '+FormatCurr('0.####', curr));
  ShowMessage('0.0000 : '+FormatCurr('0.0000', curr));
  ShowMessage('');

  // Scientific format
  ShowMessage('0.0000000E+00 : '+FormatCurr('0.0000000E+00', curr));
  ShowMessage('0.0000000E-00 : '+FormatCurr('0.0000000E-00', curr));
  ShowMessage('#.#######E-## : '+FormatCurr('#.#######E-##', curr));
  ShowMessage('');

  // Include freeform text
  ShowMessage('"Value = "0.0 : '+FormatCurr('"Value = "0.0', curr));
  ShowMessage('');

  // Different formatting for negative numbers
  curr := 1234.567;
  ShowMessage('0.0 : '+FormatCurr('0.0'              , -curr));
  ShowMessage('0.0 "CR";0.0 "DB" : '+
              FormatCurr('0.0 "CR";0.0 "DB"', -curr));
  ShowMessage('0.0 "CR";0.0 "DB" : '+
              FormatCurr('0.0 "CR";0.0 "DB"', curr));
  ShowMessage('');

  // Different format for zero value
  curr := 0.0;
  ShowMessage('0.0 : '+FormatCurr('0.0' , curr));
  ShowMessage('0.0;-0.0;"Nothing" : '+
              FormatCurr('0.0;-0.0;"Nothing"', curr));
end;
Show full unit code
   ##### : 1235
   00000 : 01235
   0     : 1235
   #,##0 : 1,235
   ,0    : 1,235
  
   0.#### : 1234.567
   0.0000 : 1234.5670
  
   0.0000000E+00 : 1.2345670E+03
   0.0000000E-00 : 1.2345670E03
   #.#######E-## : 1.234567E3
  
   "Value = " : Value = 1234.6
  
   0.0 : -1234.6
   0.0 "CR";0.0 "DB" : 1234.6 DB
   0.0 "CR";0.0 "DB" : 1234.6 CR
  
   0.0 : 0.0
   0.0;-0.0;"Nothing" : Nothing