This is used to format numerical or other types of data into a string according to the provided format string. The format string is a standard C format string. A format string can contain both text to be output to the string and format specifiers which are used to output data from another input port to the string. The input ports for this block will be created based on the format string entered in the parameter. To output a % to the output use %%.
A format specifiers has the following form %[flags][width][.precision][length]specifier
flags
Description
-
Left-justify within the given field. Right justification is the default.
+
Forces a plus or minus sign to precede the number. By default, only negative numbers are preceded with a minus sign.
(space)
Inserts a blank space before the value if no sign is going to be written.
#
Used with o, x or X specifiers the value is preceeded with 0, 0x or 0X respectively for values other than zero.
Used with a, A, e, E, f, F, g or G it forces the output to contain a decimal point even if no more digits follow.
0
Left-pads the number with zeroes instead of spaces.
width
Description
(number)
Minimum number of characters to be printed. If the value to be printed is shorter than this number, the result is padded. The value is not truncated if the result is larger.
*
The width is specified with an additional input port, not in the format string.
.precision
Description
.number
For d, i, o, u, x and X specifiers, this is the minimum number of digits to be written. If the value to be written is shorter than this number, the result is padded with leading zeros. The value is not truncated if the result is longer.
For a, A, e, E, f and F specifiers, this is the number of digits to be printed after the decimal point. The default value is 6.
For g and G specifiers, this is the maximum number of significant digits to be printed.
For s: this is the maximum number of characters to be printed.
.*
The precision is specified with an additional input port, not in the format string.
The length field modifies the default data type of the incoming port for a specifier.