English
Language : 

NSB8 Datasheet, PDF (96/158 Pages) List of Unclassifed Manufacturers – BASIC interpreter for Z80 family
grifo®
ITALIAN TECHNOLOGY
FORMATTED PRINTING
NOTE:
Read section USING NUMBERS and statement PRINT before beginning this section!
REGULAR AND E FORMAT NUMBER PRINTING
Normally, BASIC will choose between regular form and exponential/scientific form for the most
appropriate method to PRINT a numeric value. BASIC chooses the methods which will result in the
most concise printed figure. Note that a space before each regular number is automatically printed.
3.1415
.7319
-8.03
-.04
When a numeric value is too large or too small to PRINT in regular form, BASIC will automatically
use E format. E format consists of a space, a minus sign if the number is negative, the first digit of
the mantissa, a decimal point (if there are any digits left in the mantissa), any other mantissa digits,
an E (to denote the beginning of the exponent), a plus or minus sign to denote the sign of the exponent,
and the two digits of the exponent itself ( the first digit may be 0). Here are some numbers in E format:
1.4073749E+14
-2E-09
-5.4128376E+13
When BASIC chooses the format of printed values, the PRINT statement is in free format, i.e. BASIC
is free to PRINT the values using the most concise format. Sometimes, however you may want
certain values to be printed only in E format, or only with two decimal places, or only as integers (with
no decimal points). In other words, you may want to determine the format under which these numbers
will be printed, as opposed to letting the computer choose. To do this, BASIC permits you to include
numeric format specifications within the output lists of PRINT statements. These format specifications
always begin with a percent sign (%).
WHAT IS A FORMATTED NUMBER?
A programmer formatted (as opposed to a free formatted) number always takes up exactly a given
number of spaces on the printed line. This is called the field with. The field width is defined by the
programmer in the format specification, and must reserve enough character positions in the printed
line to hold all the characters in the number as printed. A field width of 6, for example, is too small
to accomodate the number 1234.56 because 7 character positions are actually required (six for the
digits, and one for the decimal point!). Also remember to leave room for plus or minus signs if they
might occur in the number, as well as the letter “E”, if E format is being used to display a number
in scientific notation. If the specified field isn’t wide enough to PRINT a given number, then a
FORMAT ERROR will occur when an attempt is made to PRINT the number using that format.
The next few examples will make use of I format to illustrate some general points about BASIC’s
formatting mechanism. Only numbers with integer values may be printed using I format. The I
Page 84
NSB8
Rel. 5.10