The PRINT USING form is used to format the results of calculations where real number results
would produce an untidy array of decimal places. It is a complicated concept that is best appreciated
through practical examples, since the technical form:
PRINT [#stream expression,,
I
[<print list)][using clause,][separator,]
Could be justly described as non-user-friendly, especially since the using clause, further divides
down to:
USING <string expresion>; [<using list>]
where the <using list> further subdivides to
<expression>[<separator><expression>]*
Try the following:
PRINT 123.456, USING “###.##“;4567.896
the result..
123.456 %4567.90
. . ..illustrates several points. Firstly the item to be printed before the USING clause is not affected.
Secondly, the USING clause allocates the number of ‘output’ positions available for the print item
following (which may be a variable of course), and if this item exceeds the allocated space to the left
of the decimal point, it still displays, but uses the % to indicate that an overflow has occured. Next,
the comma after 12 3
.4
5 6 caused the following number to be printed at the start of the next print
zone. If it had been a semi-colon, the number would have been printed alongside the 12 3
.4
5 6 one
space to the right. Numbers are always separated by one space when printed on the same line
-
for
obvious reasons!
Finally note that the expression is rounded and does not simply discard the digit(s) beyond the last
place used in the format.
Try this:
PRINT 123.456, USING “#####.##+“;4567.899
. . ..and the sign appears at the end of the formatted number. A minus sign will precede a negative
number by default.
PRINT USING is a very useful facility in producing any form of tabulated result output, It will
always warn you if the format specified is too restrictive (using the % ).
Summary of Contents for CPC464
Page 1: ......
Page 102: ...PRINT 10 AND 12 Results in 8 PRINT 10 AND 1000 Results in 8 again ...
Page 118: ...TO DO DRAW THIS PAGE ...
Page 219: ...actual value may be made to vary during the execution of a program ...
Page 240: ...Text and WINDOW planner Mode 2 80 Columns ...
Page 241: ......