Format - AMX NETLINX PROGRAMMING LANGUAGE Manual

Programming language
Table of Contents

Advertisement

Keywords & Run-Time Library Functions (Cont.)

FORMAT

NetLinx Programming Language Reference Guide
Provides a mechanism similar to 'C's printf statement for formatting the dis-
play of numbers. This function is similar to ITOA but is infinitely more powerful.
CHAR[] FORMAT(CHAR FormatLine[],CHAR Value)CHAR[]
FORMAT(CHAR FormatLine[],WIDECHAR Value)CHAR[]
FORMAT(CHAR FormatLine[],INTEGER Value)CHAR[] FORMAT(CHAR
FormatLine[],SINTEGER Value)CHAR[] FORMAT(CHAR
FormatLine[],LONG Value)CHAR[] FORMAT(CHAR
FormatLine[],SLONG Value)CHAR[] FORMAT(CHAR
FormatLine[],FLOAT Value)CHAR[] FORMAT(CHAR
FormatLine[],DOUBLE Value)
Parameters:
• FormatLine: A formatted string of text that defines how the (return) string
should be formatted. The format string contains plain characters and a
conversion specification. Plain characters are copied, as is, directly.
Conversion characters conform to the following format:
%[flags][width][.prec]type
- flags: Output justification, numeric signs, decimal points, trailing zeros,
octal and hex prefixes. By default, output is right justified. Use a '-' to left justify
as in %-5d.
-: Causes left justification, padding with blanks
0: Zeros are used to pad instead of spaces if a field length is given.
+: Output always begins with + or -.
Blank: Positive values begin with a blank.
- width: Minimum number of characters to print. If the output would be less
than this width, it is padded with spaces to be width characters wide. If the
output is larger than width the entire output is provided (i.e. it is not truncated).
- .prec: Maximum number of characters to print or number of digits to the
right of the decimal point for a float or double type.
- type: Conversion type:
c
: Value is treated as an integer, and presented as the character with that
ASCII value.
d
: Value is treated as a signed integer, and presented as a decimal number.
f
: Value is treated as a double, and presented as a floating-point number.
o
: Value is treated as a signed integer, and presented as an octal number.
u
: Unsigned integer.
x
: Value is treated as an integer and presented as a hexadecimal number
(with lowercase letters).
X
: Value is treated as an integer and presented as a hexadecimal number
(with uppercase letters).
%
: A literal percent character.
• Value: The value to be converted to a string.
The result is a formatted text string.
fTemperature = 98.652
STR = FORMAT('The current temperature is
%3.2f',fTemperature)
// Displays "The current temperature is 98.65"
The table below shows some examples of the output of FORMAT for several dif-
ferent format lines and values:
FORMAT Statement
FORMAT('%-5.2f',123.234)
FORMAT('%5.2f',3.234)
FORMAT('%+4d',6)
Reserved Identifiers
Result of FORMAT function
'123.23'
'3.23'
'+6'
127

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Netlinx studio 2

Table of Contents