FORMAT
Specifies the numerical precision format for subsequent PRINT and $STR commands.
Syntax:
FORMAT m.n FORMAT m.n EXP FORMAT m [INT] FORMAT "C_format_string" [LIT]
Discussion:
The integers m and n are separated by a decimal point. The values for m and n used must be explicit, i.e. values stored as variables cannot be used. The value m refers to the total number of characters to be printed, even though some of them may be blank. The value n refers to the number of places to display after the decimal point. Therefore, FORMAT 8.4 will cause subsequent PRINT commands to print 8 characters, with 4 numbers after the decimal point. FORMAT .5 will cause PRINT to show 5 decimal places, and as many total places as needed. FORMAT only affects numeric output from PRINT. If a number is too large to fit within the m decimal places, then the m portion of the FORMAT command will be ignored.
The optional keyword EXP after the m.n expression indicates exponential notation should be used.
The optional keyword INT indicates the value should be first converted to an integer and printed in integer format using the number of places specified by m.
The optional keyword LIT (for literal) indicates the value should be printed according to the "C" language format specifier. The C format specification can be found in any programming reference for the C language.
Example:
The macro:
X = 5 FORMAT 5.3 PRINT "FORMAT 5.3 :", X FORMAT 12.2 EXP PRINT "FORMAT 12.2 EXP :", X FORMAT 6 INT PRINT "FORMAT 6 INT :", X FORMAT "%#06i" LIT PRINT "FORMAT %#06i LIT :", X
will produce this output:
FORMAT 5.3 :5.000
FORMAT 12.2 EXP : 5.00E+000
FORMAT 6 INT : 5
FORMAT %#06i LIT :000005
Next: