PRECISION statement

Syntax

PRECISION expression

Description

Use the PRECISION statement to control the maximum number of decimal places that are output when the system converts a numeric value from internal binary format to an ASCII character string value.

expression specifies a number from 0 through 9. Any fractional digits in the result of such a conversion that exceed the precision setting are rounded off.

If you do not include a PRECISION statement, a default precision of 4 is assumed. Precisions are stacked so that a BASIC program can change its precision and call a subroutine whose precision is the default unless the subroutine executes a PRECISION statement. When the subroutine returns to the calling program, the calling program has the same precision it had when it called the subroutine.

Trailing fractional zeros are dropped during output. Therefore, when an internal number is converted to an ASCII string, the result might appear to have fewer decimal places than the precision setting allows. However, regardless of the precision setting, the calculation always reflects the maximum accuracy of which the computer is capable (that is, slightly more than 17 total digits, including integers).

If expression evaluates to the null value, the PRECISION statement fails and the program terminates with a run-time error message.

Example

A = 12.123456789
PRECISION 8
PRINT A
PRECISION 4
PRINT A

This is the program output:

12.12345679
12.1235