## Cobol: Puzzled by results of COBOL Compute with and w/o Rounded option

On Tue, 14 Oct 2008 16:49:51, Tony Girgenti wrote:

> If i multiply this out on a calculator:
> 142.79 / 110.23 * 100.000 = 129.5382
>
> My puzzlement lies in the mystery of why a ROUNDED option causes less
> rounding than a COMPUTE without the ROUNDED option.
>
> I'm more concerned about finding out a way to get the answer of:
> LINE-ITEM-UNIT-PRICE= 129.54
> LINE-ITEM-UNIT-COST= 129.538
>
> I'm not so concerned about why it is happening as much as how to make it
> give the results I want.
>
> Any help would be gratefully appreciated.

Here is how I made it work for me:

05 LINE-ITEM-UNIT-PRICE PIC S9(5)V9999 COMP VALUE 0.
05 LINE-ITEM-UNIT-PRICE2 PIC S9(5)V99 COMP VALUE 0.
05 LINE-ITEM-UNIT-COST PIC S9(5)V9999 COMP VALUE 0.
05 LINE-ITEM-UNIT-COST2 PIC S9(5)V99 COMP VALUE 0.
05 STOP-TARIFF-RATE PIC S9(5)V9999 COMP VALUE 142.79.
05 STOP-COST-RATE PIC S9(5)V9999 COMP VALUE 142.79.
05 ORDER-TOTAL-WEIGHT PIC S9(5)V9999 COMP VALUE 110.23.
05 OHP PIC S9(3)V9999 COMP VALUE 100.

.. . .

COMPUTE LINE-ITEM-UNIT-PRICE ROUNDED =
STOP-TARIFF-RATE / ORDER-TOTAL-WEIGHT * OHP
ON SIZE ERROR
MOVE ZEROES TO LINE-ITEM-UNIT-PRICE.

COMPUTE LINE-ITEM-UNIT-COST ROUNDED =
STOP-COST-RATE / ORDER-TOTAL-WEIGHT * OHP
ON SIZE ERROR
MOVE ZEROES TO LINE-ITEM-UNIT-COST.

COMPUTE LINE-ITEM-UNIT-PRICE2 ROUNDED =
LINE-ITEM-UNIT-PRICE.
COMPUTE LINE-ITEM-UNIT-COST2 ROUNDED =
LINE-ITEM-UNIT-COST.

.. . .

ROUNDED RESULTS:
LINE-ITEM-UNIT-PRICE = +00129.5380
LINE-ITEM-UNIT-COST = +00129.5380
LINE-ITEM-UNIT-PRICE2= +00129.54
LINE-ITEM-UNIT-COST2= +00129.54

HTH

Jim

* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *