RDN - Round Nearest #

Round the value in Operand 2 to the nearest value of Operand 3, and store the result in Operand 1.

Round Nearest allows the user to specify, in Operand 3, the level of rounding. For example, it is acceptable to round to the nearest 2 decimal places with an Operand 3 value of .01, or to round to the nearest half hour with an Operand3 value of .5.

Examples:

Operand 2 Operand 3 Result (stored in Operand 1)
1011.398230.1 1011.4
1011.394230.005 1011.395
3.6 0.5 3.5

It is even acceptable to round to the nearest .25 (i.e. quarter of an hour). The program will accept any value in Operand 3 and round to it.

Statement
Divide the value in PC 100 by 2, and round the resulting value to the nearest dollar.

LineCMDOTOperand 1OPEROTOperand2OTOperand3If Goto Else GoTo
00010 LET V PC 100 DIV BY 2 DIV PC 100 N 2 00020
00020 LET PC 100 RDN V PC 100 DIV BY 2 N 1 99999
99999 EXIT 99999


Notes #

Click to create a new notes page