Contents Previous Next Subchapters

Setting Floating Point Output Formats
Syntax format real form
format double 
form
format complex 
form
See Also format and format int

Menu Command
Command | Numeric Format . . .

Description
Sets the output format for the specified type of matrix, where form is a character row vector. If form is an empty vector, the output format is reset.

Tutorial

Fixed Format
If form begins with the character "f", numeric output will be right-justified in the number of columns specified by the integer following the "f". A decimal point and integer may then follow, in which case the second integer specifies the number of digits to the right of the decimal point for numeric output.

If you enter
     format real "f5"
     x = [1.2, 2.4, 3.6]
     x
O-Matrix will respond
     [     1 ,     2 ,     4 ]
Note that the values are rounded to the nearest integer. If you continue by entering
     format real "f5.2"
     x
O-Matrix will respond
     [  1.20 ,  2.40 ,  3.60 ]
The format statement also affects the values output by the write function. If you enter
     x = double(x)
     format double "f5.2"
     write("screen", x)
O-Matrix will respond
       1.20   2.40   3.60
In addition, the format statement affects the values returned by the ntoa function. If you enter
     x = complex(x)'
     format complex "f5.2"
     ntoa(x)
O-Matrix will respond
     ( 1.20, 0.00)
     ( 2.40, 0.00)
     ( 3.60, 0.00)

Exponential Format
If form begins with the character "e", numeric output will be expressed in scientific notation and right-justified in the number of columns specified by the integer following the "e". A decimal point and integer may then follow, in which case the second integer specifies the number of digits to the right of the decimal point in the mantissa.

If you enter
     format real "e12.3"
     x = [1.1, 10.1, 100.01]
     x
O-Matrix will respond
     [   1.100e+000 ,   1.010e+001 ,   1.000e+002 ]
The "e", the sign of the exponent, and the exponent itself combine to occupy five columns of output.

Free Format
If form begins with the character "g", numeric output will be right-justified in the number of columns specified by the integer following the "g". A decimal point and integer may then follow, in which case the second integer specifies the number of digits of precision. If a number cannot be output in decimal notation using the specified number of digits of precision, it will be displayed in scientific notation.

If you enter
     x = [1.1, 10.1, 100.01]
     format double "g12.2"
     double(x)
O-Matrix will respond
     [          1.1 ,            10 ,      1e+002 ]

Field Width
All of the formats above will produce stared output if the number cannot not be represented in the specified number of columns with the specified precision. If you enter
     x = 12345r0
     format complex "f5.2"
     x
O-Matrix will respond
     (*****,*****)
On the other hand, if you just specify the type of formatting, "f", "e" or "g", O-Matrix will adjust the number of columns and decimal places to fit the value being printed. If you continue the example above by entering
     format complex "g"
     x
O-Matrix will respond
     (12345,0)
("g" is the default setting for the O-Matrix floating point output values.)

Resetting Format
The commands
     format real ""
     format double ""
     format complex ""
reset the floating point formats to their default values.