format

Specifies the default format for numeric output.

Syntax

format, %[width].[precision][type], [list/array/matrix]

Input

width
An optional parameter that specifies the minimum number of characters to be printed.
precision
An optional parameter that specifies the number of digits to the right of the decimal point.
type
An optional parameter that specifies the format of the output:
i/d
integer
f
floating point
e/E
scientific notation
g/G
auto-format
o
octal
x/X
hexadecimal
c/C
single character
s/S
string
optional parameter
An optional parameter that displays the output in one of three formats:
list
Displays the contents of an array as comma-separated lists.
array
Displays the contents of an array as elements inside of braces with each element in the array surrounded by braces and separated by commas.
matrix
Displays the contents of an array as rows and columns of values bounded by vertical bars.

Example

Example 1
Template:
{format, %i, list}
{square1 = { {1.3, 2.9},
            {3.1, 4.2} } }
{square1}
{square1, %i, array}
{square1, %i, matrix}
Output:
{1, 2}, {3, 4}
{ {1, 2}, {3, 4} }
| 1 2 |
|     |
| 3 4 |
Example 2
Template:
{format, %9.7f}
{sin(PI/4)}
{sin(PI/4), %5.2f}
Output:
0.7071067
0.71

Comments

The format of numeric output is designated using C format descriptors. Numbers can be formatted as integer, octal, hexadecimal, floating point, scientific notation, value dependent, or using the default format.

The format statement affects all numeric output. When a numeric format is specified, it remains in effect until another format statement is encountered. The default format can be overridden for individual expressions.

The optional list, array, and matrix parameters specify the default layout for matrices or arrays.

To override the default format for a particular variable, substitute a variable name for the format keyword.