A special version of the PRINT statement for formatted strings output to screen
Implemented by: dartmouth6, ansifull, hptsb, decbasic, altair12K, Applesoft, cbmv7, cbmv3.5, ataplus, atxl, msatari, level2, MSX, bwbasic, bw32, ABasiC, msamiga, QBasic, FreeBASIC
With variations:
Also written as:
PRINT USING allows the use of a "format string" as a template or "mask" for screen output of variables, specially numeric ones. This string is the first argument taken by the statement:
PRINT USING "**####.##";1.2345
In most Microsoft-based BASICs, a semicolon (;) after the format string makes the output to happen where the text cursor is, and a comma (,) will place the output in the next "tab column" (which varies among platforms). Then follows the value(s) or variable(s) whose content is to be formatted — commas are used to separate them.
Most characters in the format string are printed literally, except the following ones, which acquire special meanings and effects:
#
represents a position for one single digit of the numeric value to be printed. It is used in groups. If the value has less digits, the unused positions at the left side will be shown as blank spaces. If the integer portion of the value should have more digits than the number of positions available, the value will be printed preceded by a percent sign (%). If there is a period in the string for a decimal portion, unused positions at its right side will be shown as 0s..
indicates where the decimal separator falls among the digit positions. Floating-point values will be rounded to fit the available decimal positions. If the rounding causes the number to exceed the available positions, the value will be printed preceded by a percent sign (%).,
placed right at the left of the decimal period, will cause the number to be printed with commas as thousands separators every 3 digits to the left of the decimal period.+
before or after the digits field forces display of the value' sign, either + or - before the number.-
used after the digit positions prints a minus sign (-) after negative values. A blank space is shown in its place for positive values.**
before the digit positions causes unused leftmost positions to be filled with asterisks instead of blanks. The two asterisks themselves also add two extra digit positions to the format string.$$
, placed before the leftmost digit position, will cause a dollar sign to be printed immediately at the left of the first actually printed digit, even if the actual value occupies less positions than predicted.**$
, placed before the digits field, will cause a dollar sign to be printed immediately before the first digit position, and the occasional unused space at its left will be filled with asterisks.^^^^
, when placed after a digit position, will cause floating-point numbers to be printed in exponential notation. The number of positions for the mantissa (or more precisely significand) will be the number of #s before the carets minus one. The 10n exponent will be shown with sign and two digits. Apparently following a FORTRAN tradition, a double precision value will be shown with D instead of E.PRINT USING "#.##^^^^"; 1.234567 0.12E+01 PRINT USING "###^^^^"; 1.234567 123E-02 PRINT USING "###^^^^"; 1.2345678 123D-02
For string values, there is a smaller number of options (and their usefulness is not exactly clear):
!
prints only the first character of each string in the list of variables.PRINT USING "!"; "JOHN" J PRINT USING "!!!!"; "JOHN", "PAUL", "GEORGE", "RINGO" JPGR
&
has the meaning of "variable length field", and prints all the characters of the string(s).&
to be used with numeric values as well, with the effect of printing all the digits the value requires.\\
reserves space for 2 characters of a string value. Each blank space inserted between the slashes will add one more character position.PRINT USING "\\"; "JOHN", "PAUL", "GEORGE", "RINGO" JOPAGERI PRINT USING "\ \"; "JOHN", "PAUL", "GEORGE", "RINGO" JOHPAUGEORIN
The 1972 manual of DEC BASIC-PLUS states that, unlike regular PRINT, using a trailing colon after PRINT will have no effect with PRINT USING. A trailing semicolon will however avoid a line break after the output.
In MS-QuickBASIC and QBASIC, only a semicolon can be used between the format string and the values list.
PRINT USING clearly had no consideration for locale, right-to-left languages and such.
The implementation of PRINT USING by Altair 12kB version is pretty much similar to the one of DEC BASIC-PLUS. As such it descended to other various 8-bit BASICs. Apparently, Apple and Commodore refused to pay any extra for PRINT USING. The statement was not implemented in the Sinclair family as well.
PRINT USING is rather unique in the style of format strings it uses. In contrast, the loosely similar and contemporary C printf() function established a more versatile, more powerful and by large ubiquitous standard for formatted text output.