Original Author Paul Laughton, 2011
Page 74
De Re BASIC!
Integer values
BASIC! has only double-precision floating point numbers. It does not have an integer type. The USING$()
function supports format specifiers ("%d", "%t", "%x") that apply only to integer values.
USING$() has a special relationship with the math functions that intrinsically produce integer results.
BASIC! converts the output of these functions to floating point, for storage in numeric variables, but
USING$() can get the original integer values. For example:
PRINT USING$("", "%d", 123)
% ERROR!
PRINT USING$("", "%d", INT(123))
% No error
The functions that can produce integer values for USING$() are:
INT() BIN() OCT() HEX()
CEIL() FLOOR()
ASCII() UCODE()
BAND() BOR() BXOR()
SHIFT() TIME()
FORMAT_USING$(<locale_sexp>, <format_sexp> { , <exp>}...)
Alias for USING$(). You can use the two equivalent functions to make your code easier to read. For
example:
string$ = FORMAT_USING("", "pi is not %d", int(pi()))
Print USING$("en_US", "Balance: $%8.2f", balance)
FORMAT$(<pattern_sexp>, <nexp>)
Returns a string with <nexp> formatted by the pattern <pattern_sexp>.
Leading Sign
A negative (-) character for numbers < 0 or a space for numbers >= 0.
The Sign and the Floating Character together form the Floating Field.
Floating Character If the first character of the pattern is not "#" or "." or "-" then that character
becomes a "floating" character. This pattern character is typically a "$".
If no floating character is provided then a space character is used.
See also Overflow, below.
Decimal Point
The pattern may have one optional decimal point character (".").
If the pattern has no decimal point, then only the whole number is ouput.
Any digits that would otherwise appear after the decimal point are not output.
# Character
(before decimal,
or no decimal)
Each "#" is replaced by a digit from the number. If there are more "#" characters
than digits, then the leading "#" character(s) are replaced by space(s).
# Character
(after decimal
point)
Each "#" is replaced by a digit from the number. If there are more "#" characters
than significant digits, then the trailing "#" character(s) are replaced by zero(s).
The number of "#" characters after the pattern decimal point specifies the number
of decimal digits that will be output.
% Character
(before decimal,
or no decimal)
Each "%" is replaced by a digit from the number. If there are more "%" characters
than digits, then the leading "%" character(s) are replaced by zero(s).