Formatting Guidelines
Formatting general output, numeric output, character and string output, and matrices.
Output
Templex writes text to the specified output stream exactly as it appears in the template.
{X=3}
What is X + 2?
The answer is: {X + 2}
What is X + 2?
The answer is: 5
Templex uses standard C format descriptors to format numeric and string output. Format descriptors reserve a specific amount of space in the output text for the value. If more space is reserved than the value requires, the output text is padded with spaces. Numerical values are right justified. String values are left justified.
If no format is specified, each data type uses the default format associated with
each variable type or the default template format and the output is not padded. A
default template format is created using the Templex format
statement.
{sqrt(100), %5d}
{cos(t) + sin(3.1415/phi), %12.5f}
Of the twelve spaces in the second example, five spaces are used to display the values to the right of the decimal point. One space is reserved for the decimal point. The six remaining spaces appear to the left of the decimal point as a blank and a zero.
Extra space does not need to be reserved for the leading plus/minus sign. Some operating systems display a blank instead of a plus sign.
Numeric Output
Data Format | Descriptor | Example | Output |
---|---|---|---|
Integer | d or i |
|
|
Octal | o |
{100, %4o} |
•144 |
Hexadecimal | x or X |
{100, %4X} |
••64 |
Floating point | f |
{sin(PI/4), %6.3f} |
•0.707 |
Scientific notation | e or E |
|
|
Value-dependent | g or G |
|
|
g
and G
descriptors automatically determine whether a fixed decimal or exponential notation
format should be used, depending on the magnitude of the result. If the magnitude of
the value is large, the G
descriptor uses a capital
E
in the exponent, depending on your operating system’s
defaults.Character and String Output
Character and string values can be displayed in two output formats, as single characters or as strings. Descriptors for these formats and examples of their use are given in the following table:
Data Format | Descriptor | Example | Output |
---|---|---|---|
single character | c |
{65, %c} |
A |
character string | s |
{"This is a string", %.12s} |
This is a st |
templex.hichar
. Setting the registry key to 0
ignores foreign characters while setting the registry key to 1
supports
them. You must restart Templex to see the change as it only checks this registry key at
start up.Matrices
Matrices can be displayed in three output formats: as a comma-separated list, as a list of elements inside braces, and as rows and columns of numbers. The parameters for these three formats and examples of each are given in the following table:
Data Format | Descriptor | Example | Output |
---|---|---|---|
comma-separated lists | list |
|
|
elements inside of braces | array |
|
|
rows and columns | matrix |
|
|