Custom ASCII Protocol Formatting Options
A format specification used for definition of templates in the Custom ASCII protocol consists of three optional and one required fields.
[flags] [width] [.precision] type
Each field of the format specification is a character or a number signifying a format option. The simplest format specification contains only a type character (e.g. s or d). The optional fields for flags, width and precision control other aspects of the formatting, as follows:
flags
An optional character or characters that control justification of output and printing of signs, blanks, decimal points, and hexadecimal prefixes. More than one flag can appear in a format specification.
width
An optional number that specifies the minimum number of characters output.
precision
An optional number that specifies the maximum number of characters printed for all or part of the output field, or the minimum number of digits printed for numeric values.
type
A required character that determines whether the data is interpreted as a character, a string, or a number.
Flags
–
Left align the result within the given field width, if not preset the result will be right aligned.
+
Prefix the output value with a sign (+ or -) if the output value is of a signed type. The sign will only appears only for negative signed values (-), for positive values a space will be produced. If not present, a negative sign will only be produced for a negative signed number value.
0
If width is prefixed with 0, zeros are added until the minimum width is reached. If 0 and – appear, the 0 is ignored. If 0 is specified with an integer type character  (i, u, x, X, d) and a precision specification is also present (for example, 04.d), the 0 is ignored. If not present, no padding will occur.
#
When used with the hexadecimal type x, or X , the # flag prefixes any nonzero output value with 0, 0x, or 0X, respectively. If absent, no prefix is applied.
When used with the e, E, f  type, the # flag forces the output value to contain a decimal point in all cases. If absent, a decimal point appears only if digits follow it.
When used with the g or G type, the # flag forces the output value to contain a decimal point in all cases and prevents truncation of trailing zeros.
Ignored when used with c, d, i, u, or s.
If not present, a decimal point appears only if digits follow it and any trailing zeros are truncated.
Width
The second optional field of the format specification is the width specification. The width argument is a decimal number specifying the minimum number of characters printed. If the number of characters in the output value is less than the specified width, blanks are added to the left or the right of the values depending on whether the – flag (for left alignment) is specified until the minimum width is reached. If width is prefixed with 0, and the type is numeric, zeros are inserted until the minimum width is reached.
The width does not cause truncation, that function, if desired, is performed by the precision value.Â
.Precision
The precision field control the maximum width of the field. When specifying fields with fixed formats, it is recommended that both width and precision be specified. If precision is not specified, the length, especially for numbers, may be unpredictable.
Type
c (lower case)
Causes the numeric value provided to be produced as a lower case character (if applicable)Â rather than a number.
C (upper case)
Causes the numeric value provided to be produced as an upper case character (if applicable)Â rather than a number.
i (lower case)
Causes the numeric value provided to be produced as a signed decimal integer value.
u (lower case)
Causes the numeric value provided to be produced as an unsigned decimal integer value.
x (lower case)
Causes the numeric value provided to be produced as an unsigned hexadecimal value using lower case for a..f.
 Â
X (upper case)
Causes the numeric value provided to be produced as an unsigned hexadecimal value using upper case for A..F.
 Â
e (lower case)
Signed value having the form [ – ]d.dddd e [sign]dd[d] where d is a single decimal digit, dddd is one or more decimal digits, dd[d] is two or three decimal digits depending on the output format and size of the exponent, and sign is + or --.
E (upper case)
Identical to the e type except that E rather than e introduces the exponent.
f (lower case)
Signed value having the form [ – ]dddd.dddd, where dddd is one or more decimal digits. The number of digits before the decimal point depends on the magnitude of the number, and the number of digits after the decimal point depends on the precision.
g (lower case)
Signed value printed in f or e type, whichever is more compact for the given value and precision. The e type is used only when the exponent of the value is less than --4 or greater than or equal to the precision value. Trailing zeros are truncated, and the decimal point appears only if one or more digits follow it.
G (upper case)
Identical to the g format, except that E, rather than e, introduces the exponent.
s (lower case)
Characters are produced up to the first null character or until the precision value is reached.
NOTE: The use of any other type characters should not be attempted.