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

FloatToStrF

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

Declaration

Source position: line 0

function FloatToStrF(

  Value: Double;

  format: TFloatFormat;

  Precision: Integer;

  Digits: Integer

):String;

function FloatToStrF(

  Value: Single;

  format: TFloatFormat;

  Precision: Integer;

  Digits: Integer

):String;

function FloatToStrF(

  Value: Comp;

  format: TFloatFormat;

  Precision: Integer;

  Digits: Integer

):String;

function FloatToStrF(

  Value: Currency;

  format: TFloatFormat;

  Precision: Integer;

  Digits: Integer

):String;

function FloatToStrF(

  Value: Int64;

  format: TFloatFormat;

  Precision: Integer;

  Digits: Integer

):String;

Description

FloatToStrFconverts the floating point number valueto a string representation, according to the settings of the parameters Format, Precisionand Digits.

The meaning of the Precisionand Digitsparameter depends on the Formatparameter. The format is controlled mainly by the Formatparameter. It can have one of the following values:

ffcurrency
Money format. Valueis converted to a string using the global variables CurrencyString, CurrencyFormatand NegCurrencyFormat. The Digitsparamater specifies the number of digits following the decimal point and should be in the range -1 to 18. If Digits equals -1, CurrencyDecimalsis assumed. The Precisionparameter is ignored.
ffExponent
Scientific format. Valueis converted to a string using scientific notation: 1 digit before the decimal point, possibly preceded by a minus sign if Valueis negative. The number of digits after the decimal point is controlled by Precisionand must lie in the range 0 to 15.
ffFixed
Fixed point format. Valueis 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 Valueis negative. Following the integer part is DecimalSeparatorand then the fractional part of Value, rounded off to Digitsnumbers. 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 ffExponentor ffFixedformat, depending on wich one gives the shortest string. There will be no trailing zeroes. If Valueis less than 0.00001or if the number of decimals left of the decimal point is larger than Precisionthen scientific notation is used, and Digitsis the minimum number of digits in the exponent. Otherwise Digitsis ignored.
ffnumber
Is the same as ffFixed, except that thousand separators are inserted in the resultig 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.