FormatNumber(Value: Variant; Format: String; Var Result: String): Boolean;
Value. Value, which must be shown in the specified format.
Format. Format, according to which it is necessary to convert the Value value. A data format is generated using reserved format codes. Codes are described in the Number Format: Custom section.
Result. Variable where output value is placed.
The FormatNumber method converts a numeric value into string type in accordance with the specified format.
You can use the following formats to pass values in the Value parameter:
Integer
Double
Decimal
DateTime
TimeSpan
Currency
The format set in the Format parameter does not depend on the operating system language. When the format is being set, commas and spaces are to be used as separators.
Regional settings of the culture are taken into consideration during conversion. If the conversion has been successfully executed, the output value is saved to the variable specified in the Result parameter and the method returns True. If the conversion failed, the method returns False.
Sub UserProc;
Var
Culture: ICultureInfo;
i: Integer;
d: Double;
dc: Decimal;
dt: DateTime;
t: TimeSpan;
c: Currency;
s: String;
Begin
i := 1000;
d := 1000.123;
dc := 1000.123;
dt := DateTime.ComposeDay(2010, 12, 13);
t := TimeSpan.Compose(23, 12, 5, 10, 0);
c := 123.23;
//Convert
Culture := CultureInfo.Current;
Culture.FormatNumber(i, """Discard ""@"" items""", s);
Debug.WriteLine(s);
Culture.FormatNumber(d, "# #,0", s);
Debug.WriteLine(s);
Culture.FormatNumber(dc, "# #,00", s);
Debug.WriteLine(s);
Culture.FormatNumber(dt, "D MMMM YYYY ""y.""", s);
Debug.WriteLine(s);
Culture.FormatNumber(t, "DD"" day(days) ""HH"" hour(s) ""MM"" minute(s) ""SS ""second(s)""", s);
Debug.WriteLine(s);
Culture.FormatNumber(c, "$ 0,00 ""receipt""", s);
Debug.WriteLine(s);
End Sub UserProc;
After executing the example the development environment console displays various values converted in accordance with the specified format.
See also: