Rounding

Many programmers' headaches have been caused by unpredictable rounding of numeric values during program execution. An application such as an amortization schedule can be off by a few pennies depending on the effects of rounding. Because PRO/5 uses real decimal arithmetic, many rounding problems do not occur. Still, the programmer should be aware of where PRO/5 will perform rounding. The verbs PRECISION and FLOATINGPOINT are used to set a desired precision. PRO/5 always performs calculations with full floating-point precision. Rounding to the current precision will occur in the following cases:

  • When PRO/5 assigns the result of an expression to a variable, rounding will occur at the time of the assignment if multiplication, division, exponentiation, FPT() , MOD(), SIN(), COS(), ATN(), LOG(), FDEC(), RND(0), or SQR() were used in the expression.

  • The SETOPTS verb forces numeric rounding of intermediate results immediately after multiplication, division, addition, subtraction, and exponentiation.

  • When outputting a number through an output verb or using the STR() function, PRO/5 will round a value to the current precision if no format mask is used, or to the precision of the mask if a mask is used.

  • When comparing two numbers, PRO/5 will compare temporarily rounded versions of the numbers.

  • The ROUND() function forces rounding to occur immediately.