DelphiBasics
TFloatFormat
Type
Formats for use in floating point number display functions SysUtils unit
type TFloatFormat = (ffGeneral, ffExponent, ffFixed, ffNumber, ffCurrency);
Description
The TFloatFormat type is used by the following SysUtils functions :
 
CurrToStrF? For displaying currency values FloatToStrF For general float displaying FloatToText For formatting to an array
 
The possible values of TFloatFormat are :
 
ffGeneral
 
Defines general number formatting that aims to keep the resultant value as compact as possible. It removes trailing zeros and the decimal point where appropriate. No thousand separators are shown. Exponent format is used if the mantissa is too large for the specified Precision value of the formatting command. In this case, the Digits value (0..4) determines the minimum number of exponent digits shown. The decimal point character is determined by the DecimalSeparator variable.
 
ffExponent
 
Commonly referred to as the Scientific or Engineering format, the exponent refers to the letter E followed by a number. The number gives the power of 10 of the number. For example, E+15 means 1015. The exponent always has a + or - sign. This exponent is preceded by a number that always has one digit before the decimal place.
 
For example : 123.456 formats as 1.23456E+2 0.00123 formats as 1.23E-3
 
The using function Precision parameter gives the number of displayed digits before the E, and the Digits parameter gives the number (0..4) of digits after the E.
 
The decimal point character is determined by the DecimalSeparator variable.
 
ffFixed
 
This format again uses no thousands separator. It displays Precision digits before the decimal point, and Digits digits after. If there are too many digits before the decimal point, then the Exponent format is used instead.
 
The decimal point character is determined by the DecimalSeparator variable.
 
ffNumber
 
Same as ffFixed, except that thousand separators are used. These are defined by the ThousandSeparator variable.
 
ffCurrency
 
Same as ffNumber, but with a currency symbol (string) added, as defined by the CurrencyString variable. Additionally, the formatting is influenced by the CurrencyFormat and NegCurrFormat variables.
Notes
Note above that the Precision and Digits values of the function using TFloatFormat depend on the format chosen.
Related commands
CurrencyDecimalsDefines decimal digit count in the Format function
CurrencyFormatDefines currency string placement in curr display functions
CurrencyStringThe currency string used in currency display functions
CurrToStrFConvert a currency value to a string with formatting
DecimalSeparatorThe character used to display the decimal point
FloatToStrFConvert a floating point value to a string with formatting
NegCurrFormatDefines negative amount formatting in currency displays
ThousandSeparatorThe character used to display the thousands separator
 Download this web site as a Windows program.




 
Example code : Illustrate the 5 different types of formatting
var
  amount : Extended;

begin
  amount := 1234.56;

  // Display using ffGeneral formatting
  ShowMessage('General 4,0 = '+FloatToStrF(amount, ffGeneral, 4, 0));
  ShowMessage('General 6,0 = '+FloatToStrF(amount, ffGeneral, 6, 0));
  ShowMessage('General 6,2 = '+FloatToStrF(amount, ffGeneral, 6, 2));
  ShowMessage('General 3,2 = '+FloatToStrF(amount, ffGeneral, 3, 2));
  ShowMessage('');

  // Display using ffExponent formatting
  ShowMessage('Exponent 4,0 = '+FloatToStrF(amount, ffExponent, 4, 0));
  ShowMessage('Exponent 6,0 = '+FloatToStrF(amount, ffExponent, 6, 0));
  ShowMessage('Exponent 6,2 = '+FloatToStrF(amount, ffExponent, 6, 2));
  ShowMessage('Exponent 3,2 = '+FloatToStrF(amount, ffExponent, 3, 2));
  ShowMessage('');

  // Display using ffFixed formatting
  ShowMessage('Fixed 4,0 = '+FloatToStrF(amount, ffFixed, 4, 0));
  ShowMessage('Fixed 6,0 = '+FloatToStrF(amount, ffFixed, 6, 0));
  ShowMessage('Fixed 6,2 = '+FloatToStrF(amount, ffFixed, 6, 2));
  ShowMessage('Fixed 3,2 = '+FloatToStrF(amount, ffFixed, 3, 2));
  ShowMessage('');

  // Display using ffNumber formatting
  ShowMessage('Number 4,0 = '+FloatToStrF(amount, ffNumber, 4, 0));
  ShowMessage('Number 6,0 = '+FloatToStrF(amount, ffNumber, 6, 0));
  ShowMessage('Number 6,2 = '+FloatToStrF(amount, ffNumber, 6, 2));
  ShowMessage('Number 3,2 = '+FloatToStrF(amount, ffNumber, 3, 2));
  ShowMessage('');

  // Display using ffCurrency formatting
  ShowMessage('Currency 4,0 = '+FloatToStrF(amount, ffCurrency, 4, 0));
  ShowMessage('Currency 6,0 = '+FloatToStrF(amount, ffCurrency, 6, 0));
  ShowMessage('Currency 6,2 = '+FloatToStrF(amount, ffCurrency, 6, 2));
  ShowMessage('Currency 3,2 = '+FloatToStrF(amount, ffCurrency, 3, 2));
end;
Show full unit code
  General 4,0 = 1235
  General 6,0 = 1234.56
  General 6,2 = 1234.56
  General 3,2 = 1.23E03
  
  Exponent 4,0 = 1.235E+3
  Exponent 6,0 = 1.23456E+3
  Exponent 6,2 = 1.23456E+03
  Exponent 3,2 = 1.23E+03
  
  Fixed 4,0 = 1235
  Fixed 6,0 = 1235
  Fixed 6,2 = 1234.56
  Fixed 3,2 = 1.23E03
  
  Number 4,0 = 1,235
  Number 6,0 = 1,235
  Number 6,2 = 1,234.56
  Number 3,2 = 1.23E03
  
  Currency 4,0 = ?1,235
  Currency 6,0 = ?1,235
  Currency 6,2 = ?1,234.56
  Currency 3,2 = 1.23E03
  
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page