qb45advr.hlp (
Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
Type Conversions
◄Data Types► ◄Type Conversions► ◄Contents► ◄Index►
──────────────────────────────────────────────────────────────────────────────
Type Conversion
When necessary, BASIC converts a numeric constant from one type to another,
according to the following rules:
■ If a numeric constant of one type is set equal to a numeric variable of
a different type, the numeric constant is stored as the type declared
in the variable name, as in the following example:
A% = 23.42
PRINT A%
Output:
23
If a string variable is set equal to a numeric value, or vice versa, an
error message is generated that reads: "Type Mismatch."
■ During expression evaluation, the operands in an arithmetic or
relational operation are converted to the same degree of precision,
that of the most precise operand, as each operation is performed. Also,
the result of an arithmetic operation is returned to the final degree
of precision, as in the following example:
X% = 2 : Y! = 1.5 : Z# = 100
A! = X% / Y!
PRINT A! * Z#
Output:
133.3333373069763
Although the preceding result is displayed in double precision (because
of the double-precision variable Z#), it has only single-precision
accuracy, because the assignment to A! forced the result of X% / Y! to
be reduced to single-precision accuracy. This explains the
nonsignificant digits (73069763) after the fifth decimal place.
Contrast this with the output from the following example in which the
intermediate result of X% / Y! is retained in double precision:
X% = 2 : Y# = 1.5 : Z# = 100
PRINT X% / Y# * Z#
Output:
133.3333333333333
■ Logical operators such as AND and NOT convert their operands to long
integers if necessary. Operands must be in the range -2,147,483,648 to
+2,147,483,647 or an "Overflow" error message is generated.
■ When a floating-point value is converted to an integer, the fractional
portion is rounded, as in this example:
Total% = 55.88
PRINT Total%
Output:
56