Overload List
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.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Value | Double | scalar |
| 2 | Format | TFloatFormat | |
| 3 | Precision | Integer | |
| 4 | Digits | Integer |
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;
Overload 2: function FloatToStrF(const Value: Double; const Format: TFloatFormat; const Precision, Digits: Integer; const AFormatSettings: TFormatSettings): Substring; overload; inline;
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Value | Double | scalar |
| 2 | Format | TFloatFormat | |
| 3 | Precision | Integer | |
| 4 | Digits | Integer | |
| 5 | AFormatSettings | TFormatSettings |
Returns: Substring
Overload 3: function FloatToStrF(const Value: Single; const Format: TFloatFormat; const Precision, Digits: Integer): Substring; overload; inline;
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Value | Single | scalar |
| 2 | Format | TFloatFormat | |
| 3 | Precision | Integer | |
| 4 | Digits | Integer |
Returns: Substring
Overload 4: function FloatToStrF(const Value: Single; const Format: TFloatFormat; const Precision, Digits: Integer; const AFormatSettings: TFormatSettings): Substring; overload; inline;
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Value | Single | scalar |
| 2 | Format | TFloatFormat | |
| 3 | Precision | Integer | |
| 4 | Digits | Integer | |
| 5 | AFormatSettings | TFormatSettings |
Returns: Substring