[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] Reference for unit 'sysutils' (#rtl)

FloatToStrF

Convert a float value to a string using a given format.

Declaration

Source position: sysstrh.inc line 152

function FloatToStrF(

  Value: Extended;

  format: TFloatFormat;

  Precision: Integer;

  Digits: Integer

):string;

function FloatToStrF(

  Value: Extended;

  format: TFloatFormat;

  Precision: Integer;

  Digits: Integer;

  const FormatSettings: TFormatSettings

):string;

function FloatToStrF(

  Value: Double;

  format: TFloatFormat;

  Precision: Integer;

  Digits: Integer

):string;

function FloatToStrF(

  Value: Double;

  format: TFloatFormat;

  Precision: Integer;

  Digits: Integer;

  const FormatSettings: TFormatSettings

):string;

function FloatToStrF(

  Value: Single;

  format: TFloatFormat;

  Precision: Integer;

  Digits: Integer

):string;

function FloatToStrF(

  Value: Single;

  format: TFloatFormat;

  Precision: Integer;

  Digits: Integer;

  const FormatSettings: TFormatSettings

):string;

function FloatToStrF(

  Value: Comp;

  format: TFloatFormat;

  Precision: Integer;

  Digits: Integer

):string;

function FloatToStrF(

  Value: Comp;

  format: TFloatFormat;

  Precision: Integer;

  Digits: Integer;

  const FormatSettings: TFormatSettings

):string;

function FloatToStrF(

  Value: Currency;

  format: TFloatFormat;

  Precision: Integer;

  Digits: Integer

):string;

function FloatToStrF(

  Value: Currency;

  format: TFloatFormat;

  Precision: Integer;

  Digits: Integer;

  const FormatSettings: TFormatSettings

):string;

function FloatToStrF(

  Value: Int64;

  format: TFloatFormat;

  Precision: Integer;

  Digits: Integer

):string;

function FloatToStrF(

  Value: Int64;

  format: TFloatFormat;

  Precision: Integer;

  Digits: Integer;

  const FormatSettings: TFormatSettings

):string;

Description

FloatToStrF converts the floating point number value to a string representation, according to the settings of the parameters Format, Precision and Digits.

The meaning of the Precision and Digits parameter depends on the Format parameter. The format is controlled mainly by the Format parameter. It can have one of the following values:

ffcurrency
Money format. Value is converted to a string using the global variables CurrencyString, CurrencyFormat and NegCurrFormat. The Digits parameter specifies the number of digits following the decimal point and should be in the range -1 to 18. If Digits equals -1, CurrencyDecimals is assumed. The Precision parameter is ignored.
ffExponent
Scientific format. Value is converted to a string using scientific notation: 1 digit before the decimal point, possibly preceded by a minus sign if Value is negative. The number of digits after the decimal point is controlled by Precision and must lie in the range 0 to 15.
ffFixed
Fixed point format. Value is converted to a string using fixed point notation. The result is composed of all digits of the integer part of Value, preceded by a minus sign if Value is negative. Following the integer part is DecimalSeparator and then the fractional part of Value, rounded off to Digits numbers. If the number is too large then the result will be in scientific notation.
ffGeneral
General number format. The argument is converted to a string using ffExponent or ffFixed format, depending on which one gives the shortest string. There will be no trailing zeroes. If Value is less than 0.00001 or if the number of decimals left of the decimal point is larger than Precision then scientific notation is used, and Digits is the minimum number of digits in the exponent. Otherwise Digits is ignored.
ffnumber
Is the same as ffFixed, except that thousand separators are inserted in the resulting string.

Errors

None.

See also

FloatToStr

  

Convert a float value to a string using a fixed format.

FloatToText

  

Return a string representation of a float, with a given format.

Example

Program Example68;

{ This program demonstrates the FloatToStrF function }

Uses sysutils;

Const Fmt : Array [TFloatFormat] of string[10] =
         ('general','exponent','fixed','number','Currency');

Procedure Testit (Value :  Extended);

Var I,J : longint;
    FF : TFloatFormat;

begin
  For I:=5 to 15 do
    For J:=1 to 4 do
      For FF:=ffgeneral to ffcurrency do
        begin
        Write (Value,'(Prec: ',I:2,', Dig: ',J,', fmt : ',Fmt[ff],') : ');
        Writeln (FloatToStrf(Value,FF,I,J));
        Write (-Value,'(Prec: ',I:2,', Dig: ',J,', fmt : ',Fmt[ff],') : ');
        Writeln (FloatToStrf(-Value,FF,I,J));
        end;
end;

Begin
  Testit (1.1);
  Testit (1.1E1);
  Testit (1.1E-1);
  Testit (1.1E5);
  Testit (1.1E-5);
  Testit (1.1E10);
  Testit (1.1E-10);
  Testit (1.1E15);
  Testit (1.1E-15);
  Testit (1.1E100);
  Testit (1.1E-100);
End.

Documentation generated on: Jun 22 2020