FORMAT
Returns a string including an inserted formatted value.
WebVue support - Yes.
Unlike the similar PRINTF instruction found in many programming languages, FORMAT only supports one formatted variable per use.
Syntax
StrVal = FORMAT("xxxxx%FormatString yyyyy", Variable);
Return type: STR.
Argument | Meaning |
xxxxx | A text string that will appear before the formatted value in the returned string. Optional. |
yyyyy | A text string that will appear after the formatted value in the returned string. Optional. |
FormatString |
A placeholder string that determines the format and position of the inserted value. It starts with the character % and contains Width, Precision and Modifier. |
Width | A number specifying the width of the inserted variable (as a number of characters). If this is preceded by a minus sign the characters will be left justified, otherwise they will be right justified. Optional. |
Precision | The maximum number of characters of the inserted variable, the maximum number of digits for an integer or the number of digits to the right of the decimal point for a floating point number. It is always preceded by a full stop. Optional. |
Modifier | A character specifying how the variable is to be returned. Type STR. |
Variable | The variable which value is to be formatted. |
The whole of the first argument is enclosed in double quote marks and contains no separators other than the % sign that marks the start of the placeholder string, e.g. "Result = %d approx.".
Execution
A variable's value is returned within a string as a formatted sub-string. The modifier must correspond to the variable type.
Modifier | Variable type | Return format |
d, i | Integer | Decimal number. |
o | Integer | Octal number (not preceded by a zero). |
x, X | Integer | Hexadecimal number, using abcdef (x) or ABCDEF(X) for 10 to 15 (not preceded by a 0x). |
u | Integer | Unsigned decimal number. |
c,C | Integer | Single character for the specified ASCII code. |
s | Str | Returns a single-byte character string from a string up to the first null or up to the number of characters specified by Precision. |
f | Double | Decimal notation of the form [-]m.dddddd, where the number of d's is given by the precision (6 by default). |
e, E | Double | Exponential notation of the form [-]m.dddddde±xx or [-]m.ddddddE±xx, where the number of d character positions is given by Precision (6 by default). |
g, G | Double |
Equivalent to %e or %E if the exponent is less than -4 or greater than or equal to Precision; otherwise is equivalent to %f. Zeros or the terminating decimal point are not returned. |
ld | Long | Four-byte integer. |
lld | LongLong | Eight-byte integer. |
Example
For an example of how the FORMAT command displays various text strings, select the Example link above.