System Functions

PRC( )

Round Number to Precision

Format

PRC(num[,precision][,ERR=stmtref])
  
Where: 

num

Value to be rounded. Numeric expression.

precision

Precision to which to round. Optional. Numeric expression. Integer from 0 to 14. If omitted, rounding is done to the current precision in effect.

stmtref

Program line number or statement label to which to transfer control.

Returns

Numeric value, rounded to a set precision.

Description

The PRC( ) function returns a given numeric value (num) rounded to the set precision.

If a precision parameter is supplied, the PRC( ) function rounds the value based on the new precision. If precision is not supplied, then the value is rounded to the current PRECISION in effect.

Note:
One exception to the above: A ROUND ON directive will truncate longer values to the current PRECISION in effect.

If you use an invalid value (e.g. >14), PxPlus returns Error #41: Invalid integer encountered (range error or non-integer).

See Also

PRECISION Change Current Precision
ROUND Control Rounding
FLOATINGPOINT Switch to Scientific Notation

Example

A=prc(1.3456);
print A,
A=prc(1.3456,0);
print @(15),A,
A=prc(1.3456,3);
print @(25),A,
A=prc(1.3456,2);
print @(40),A,

->run

The results will vary, depending on current precision and rounding:

PRECISION 2, ROUND OFF

PRECISION 2, ROUND ON

PRECISION -1

1.35

1.35

.13456E+0

1

1

1 .1E+01

1.346

1.35

.1346E+01

1.35-

1.35-

.135E+01-