Function Block STR_FORMAT

The function block STR_FORMAT returns a formatted string.

This function block corresponds to the sprintf function in C++.

Note: This function block can have more than two inputs. You can right-click on the function block to add another input.

Input Format

The input defines the formatting. It consists of zero or more instructions: Normal characters (except %), which are directly copied into the result, and conversion instructions that each retrieve their own parameters.

In this case, the conversion instruction follows this prototype:

%[ArgNum$][Flags][Width][.Precision]Specifier.
ArgNum

An integer followed by a dollar sign $ that specifies the number of the input STR# to be used for conversion.

Flags
Flag Description
- Left-aligned within the specified field width; right-aligned is the default
+ Positive numbers with a plus sign +; by default, only negative numbers are output with negative signs
(Space) Fills the result with spaces. This is the default.
0 Pads to the left with zeros. With the s specifier, this can also pad to the right with zeros.
'(Character) Fills the result with the specified character.
Width

An integer that specifies how many characters (minimum) the conversion result should have.

Precision

The meaning of a point . followed by an integer depends on the specifier:

  • For specifiers e, E, f and F: This sets the number of decimal places to be output after the decimal separator (default is 6).
  • For specifiers g and G: The maximum number of significant decimal places to be output.
  • For the s specifier: Acts like a cutoff point that specifies a maximum number of characters in the string.

Note: If the dot is specified without an explicit value for precision, 0 is assumed.

Specifier
Specifier Description
% A percent sign. No parameter required.
b The parameter is treated as an integer and output as a binary number.
c The parameter is treated as an integer and output as a character from the ASCII character set.
d The parameter is treated as an integer and output as a (signed) decimal number.
e The parameter is treated as a number in scientific notation (e.g., 1.2e+2). The precision specifies the number of characters after the decimal point.
E Like specifier e, but writes an uppercase letter (e.g., 1.2E+2).
f The parameter is treated as a floating-point number and output as a floating-point number (depending on the locale).
F The parameter is treated as a floating-point number and output as a floating-point number (independent of the locale).
g General format.
Let P be the precision, if not zero, 6 if the precision is not specified or 1 if the precision is zero. Then, if a conversion using E would have an exponent of X:
If P > X ≥ −4, the conversion with specifier f and precision P - (X + 1). Otherwise like with specifier e and precision P - 1.
G Like specifier g, but uses E and F.
o The parameter is treated as an integer and output as an octal number.
s The parameter is treated as a string and output.
u The parameter is treated as an integer and output as an unsigned decimal number.
x The parameter is treated as an integer and output as a hexadecimal number (with lowercase letters).
X The parameter is treated as an integer and output as a hexadecimal number (with uppercase letters).

Warning: The specifier c ignores padding and width.

Warning: Attempting to use the combination of string width specification and character sets that expect more than one byte per character leads to unpredictable results.

Variables are converted to a type suitable for the specifier:

Type Specifier
String s
Integer d, u, c, o, x, X, b
Float g, G, e, E, f, F

Input STR1..STR#

The input or multiple inputs define the respective value to be replaced in the specified string at the input FORMAT.

Output

Returns the generated string.