Substr.FloatToStrF Method

Overload List

#SignatureDescription
1function FloatToStrF(const Value: Double; const Format: TFloatFormat; const Precision, Digits: Integer): Substring; overload; inline;Value as text in Format, its digits correctly rounded.
2function FloatToStrF(const Value: Double; const Format: TFloatFormat; const Precision, Digits: Integer; const AFormatSettings: TFormatSettings): Substring; overload; inline;
3function FloatToStrF(const Value: Single; const Format: TFloatFormat; const Precision, Digits: Integer): Substring; overload; inline;
4function FloatToStrF(const Value: Single; const Format: TFloatFormat; const Precision, Digits: Integer; const AFormatSettings: TFormatSettings): Substring; overload; inline;

Overload 1: function FloatToStrF(const Value: Double; const Format: TFloatFormat; const Precision, Digits: Integer): Substring; overload; inline;

Value as text in Format, its digits correctly rounded.

#NameTypeDescription
1ValueDoublescalar
2FormatTFloatFormat
3PrecisionInteger
4DigitsInteger

Returns: Substring

Remarks:

Call it qualified. Precision is the number of significant digits of ffGeneral and ffExponent; above 17 they are Value's exact digits. Digits is the number of decimals of ffFixed, ffNumber and ffCurrency, and the minimum number of exponent digits of ffExponent. ffFixed, ffNumber and ffCurrency write a value with more integer digits than Precision as ffGeneral does. Separators and currency format come from AFormatSettings, else FormatSettings. A Precision below 1 or a negative Digits raises EConvertError: FloatToStrF: Precision 0 is outside 1 to 2147483647.

Examples

Each format, with the invariant separators.

uses Substr, System.SysUtils;

procedure Example;
var FS: TFormatSettings;
    s: Single;
begin
    FS := TFormatSettings.Invariant;
    Assert(Substr.FloatToStrF(2.5, ffFixed, 15, 2, FS) = '2.50');
    Assert(Substr.FloatToStrF(1234567.0, ffNumber, 15, 1, FS) = '1,234,567.0');
    Assert(Substr.FloatToStrF(0.000123456, ffExponent, 3, 2, FS) = '1.23E-04');
    Assert(Substr.FloatToStrF(1e20, ffFixed, 15, 2, FS) = '1E20');
    Assert(Substr.FloatToStrF(0.1, ffGeneral, 20, 0, FS) = '0.10000000000000000555');
    s := 0.1;
    Assert(Substr.FloatToStrF(s, ffGeneral, 7, 0, FS) = '0.1');
end;
See Also: Substr.FloatToStr, Substring.Parse, Substring.Parse, Substring.Parse, Substring.Parse, Substring.Parse, Substring.Parse, Substring.Parse, Substring.Parse

Overload 2: function FloatToStrF(const Value: Double; const Format: TFloatFormat; const Precision, Digits: Integer; const AFormatSettings: TFormatSettings): Substring; overload; inline;

#NameTypeDescription
1ValueDoublescalar
2FormatTFloatFormat
3PrecisionInteger
4DigitsInteger
5AFormatSettingsTFormatSettings

Returns: Substring

Overload 3: function FloatToStrF(const Value: Single; const Format: TFloatFormat; const Precision, Digits: Integer): Substring; overload; inline;

#NameTypeDescription
1ValueSinglescalar
2FormatTFloatFormat
3PrecisionInteger
4DigitsInteger

Returns: Substring

Overload 4: function FloatToStrF(const Value: Single; const Format: TFloatFormat; const Precision, Digits: Integer; const AFormatSettings: TFormatSettings): Substring; overload; inline;

#NameTypeDescription
1ValueSinglescalar
2FormatTFloatFormat
3PrecisionInteger
4DigitsInteger
5AFormatSettingsTFormatSettings

Returns: Substring