Function Format (const format: string; const ARGs: array of const): string;
Format String description:
"%" [Index ":"] ["-"] [width] ["." prec] Type
(1) The formatted string must start with %
(2) [Index ":"] index refers to the serial number of each item to be displayed in the ARGs parameter list. For example, The args is
['A', 'C'], then the 'A' index is 0, while the 'C' index is 1.
So there will be no index value greater than 1.
Format ('% 2: S % 1: S % 0: s', ['1st', '2nd', '3rd']);
Result: '3rd 2nd 1st'
(3) ["-"] This identifier fills in spaces on the right when the number of characters to be displayed is less than [width;
If ["-"] is not added, fill in spaces on the left.
Format ('(% 4 s)', ['a']); Result: 'A'
(4) [width] width
Specifies the number of characters to be displayed. If the width to be displayed is greater than [width ],
The width. Otherwise, fill in spaces or other characters as required.
(5) ["." prec] precision
This is for floating point numbers. It generally refers to the number of digits after the decimal point.
(6) type (see below)
The possible values of type include the following:
(1) d signed decimal number
ARGs must be a signed integer. If ["." prec] is added to the formatted string
If the length is less than the given number of precision, fill 0 in the front side; if the length is greater than the number of precision, display according to the actual length.
Format ('(%. 3d)', [99]); Result: '(099 )'
(2) U unsigned decimal number
ARGs must be an unsigned integer. Other features are the same as those of D.
(3) e Scientific and Technological Law
Data is displayed in the form of '-D. DDD... e + DDD '.
ARGs must be a floating point number. If it is a negative number, a symbol is displayed at the beginning; Before the decimal point
A number is always displayed. the number before the decimal point is determined by ["." prec,
If ["." prec] is not specified, the default value is 15 bits. If the actual number length exceeds the specified length
["." Prec], then the digit that has just exceeded is rounded down. The exponential sign E always follows the plus sign or
Minus signs, followed by at least three digits.
(4) f fixed
ARGs must be a floating point number. The converted format is '- DDD. DDD.
If you want to convert a negative value, there is a negative number before. Number after the decimal point
Determined by ["." prec. If ["." prec] is not specified, the default value is 2 bits.
(5) g average
ARGs must be a floating point number.
The converted number is always as short as possible (possibly in the f or E format ). The length of a significant number
It is determined by ["." prec]. The default value is 15 bits (including the integer and decimal places ). 0 before and after the number will be removed,
The decimal point is displayed only when necessary. If the number on the left of the decimal point is less than or equal to the specified precision,
The F display format is used only when the entire value is greater than or equal to 0.00001. Otherwise, e is used)
(6) n ARGs must be a floating point number. The format is the same as that of F. The difference is that the kilobytes of characters are displayed, for example, 1,123,444.
(7) m currency type
ARGs must be a floating point number. You can use the control panel to display currency symbols. Decimal point
The number of digits is determined by ["." prec]. If ["." prec] is not used, the default value is 2.
(8) P pointer
ARGs must be a pointer value.
Converts a pointer to an 8-character hexadecimal string.
(9) s string
ARGs must be a character, string, or pchar value.
If ["." prec] is specified and the actual length of the string is greater than ["." prec], the string is truncated from left to right.
Specify the number of strings with precision, and delete the remaining strings.
(10) x hexadecimal
ARGs must be an integer.
If ["." prec] is used, fill in the missing parts with 0.
Note: [Index ":"] [width] ["." prec] can be in the following format:
Format ('% *. * F', [8, 2,123.456])
It is equivalent to format ('% 8.2f', [123.456]).
Format ('X = % d', [12]); // 'X = 12' // The most common
Format ('X = % 3d ', [12]); // 'X = 12' // specify the width
Format ('X = % F', [12.0]); // 'X = 12.00 '// floating point number
Format ('X = %. 3f', [12.0]); // 'X = 100' // specify the decimal point
Format ('X = %. * F', [5, 12.0]); // 'X = 100' // dynamic configuration
Format ('X = %. 5D ', [12]); // 'X = 100' // Add 0
Format ('X = %. 5x ', [12]); // 'X = 20.c' // hexadecimal
Format ('X = % 1: d % 0: d ', [12, 13]); // 'X = 100' // use the index
Format ('X = % P', [nil]); // 'X = 100' // pointer
Format ('X = % 1.1e ', [00000000]); // 'X = 1.2e + 001' // scientific note
Format ('X = % ', []); // 'X = % '// get "%"
S: = format (' % S % d', [s, I]); // S: = S + strtoint (I); // connection string