SmartPascal
CurrToStrF
Function
Convert a currency value to a string with formatting SysUtils unit
1  function CurrToStrF ( Value : Currency; Format : TFloatFormat; Digits : Integer ) : string;
2  function CurrToStrF ( Value : Currency; Format : TFloatFormat; Digits : Integer; const FormatSettings : TFormatSettings ) : string;
Description
The CurrToStrF function converts a currency Value into a displayable string, with great control over the formatting via the Format, and Digits values.
 
The Digits value determines how many decimal digits are displayed.
 
The Format parameter is defined by the TFloatFormat (SysUtils) type :
 
ffCurrency  eg : ?2,345.60
ffExponent  eg : 2.3456E+04
ffFixed  eg : 2345.60
ffGeneral  eg : 2345.6
ffNumber  eg : 2,345.6

 
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.
Notes
You can change the currency string from the default (such as '$' in the USA, '?' in the UK) using the CurrencyString variable.

You can change the position of the currency string using the CurrencyFormat variable.

You can change the decimal point value by setting the DecimalSeparator character.

You can change the thousands separator value by setting the ThousandSeparator character.

The NegCurrFormat variable determines the formatting of negative amounts.

If the full number of digits before the decimal point (the mantissa) cannot be displayed, then the display reverts to the exponent (scientific) format.

See FloatToStrF and TFloatFormat for examples of all formatting options. Normally, you would probably use only the ffCurrency format.
Related commands
CurrencyDecimals Defines decimal digit count in the Format function
CurrencyFormat Defines currency string placement in curr display functions
CurrencyString The currency string used in currency display functions
DecimalSeparator The character used to display the decimal point
FloatToStrF Convert a floating point value to a string with formatting
NegCurrFormat Defines negative amount formatting in currency displays
TFloatFormat Formats for use in floating point number display functions
ThousandSeparator The character used to display the thousands separator
 
Example code : Display currency numbers as financial values
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
 
unit Unit1;
 
interface
 
uses
  SysUtils,   // Unit containing the CurrToStrF command
  Forms, Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;
 
var
  
Form1: TForm1;
 
implementation
{$R *.dfm} // Include form definitions
 
procedure TForm1.FormCreate(Sender: TObject);

var
  amount1 : Currency;

begin
  amount1 := 1234.567;

  // Display in a Currency format
  CurrencyString := '? ';
  ShowMessage('Using 4 digits = '+CurrToStrF(amount1, ffCurrency, 4));
  ShowMessage('Using 2 digits = '+CurrToStrF(amount1, ffCurrency, 2));
  ShowMessage('Using 0 digits = '+CurrToStrF(amount1, ffCurrency, 0));
end;

 
end.
Hide full unit code
   Using 4 digits = ? 1,234.5670
   Using 2 digits = ? 1,234.57
   Using 0 digits = ? 1,235