## compute with decimal number

## compute with decimal number

(OP)

Hello,

i have some problem with compute with decimal places. I have an amount without a decimal places and a field as minor unit code, where are the number of decimal places.

The compute below doesn´t work, if the minor unit code are greater than 6.

decimal = PIC 9(39V(9)6 COMP-4.

COMPUTE decimal = amount * (10 ** (dcml * -1))

With a floating-point i get the proper value

COMPUTE decimal = amount * (10 ** (dcml * -1)) + 0.0E+00

Can somebody explain that or rather make proposal for a better way ?

Regards

Bernd

i have some problem with compute with decimal places. I have an amount without a decimal places and a field as minor unit code, where are the number of decimal places.

The compute below doesn´t work, if the minor unit code are greater than 6.

decimal = PIC 9(39V(9)6 COMP-4.

COMPUTE decimal = amount * (10 ** (dcml * -1))

With a floating-point i get the proper value

COMPUTE decimal = amount * (10 ** (dcml * -1)) + 0.0E+00

Can somebody explain that or rather make proposal for a better way ?

Regards

Bernd

## RE: compute with decimal number

So split this calculation up and use the proper sizes of variables for receiving each intermediate result. Then you should be fine.

We could help you further in doing this, if necessary, but you do not give how you defined "amount" and "dcml".

Measurement is not management.

## RE: compute with decimal number

thanks.

Below the data definition:

decimal PIC 9(3)V(9)6 COMP-4

amount PIC 9(18) COMP-3

Dcml PIC 9(9).

## RE: compute with decimal number

COMPUTE decimal = amount * (10 ** (dcml * -1))

Order of ops - write your code so you split each step.

1) dcml * -1 (this might be the start of a problem) --> INT01

2) 10 ** Int01 --> INT02

3) amount * INT02 --> final result.

To follow the formula as written:

INT01 should be the same size as dcml but signed.

INT02 should be a decimal the size of the maximum of dcml.

I would try to rework the formula as well, but odds are that much can be simplified. If DCML truly has no sign and is always positive, you can apply algebra (n^-3 = 1 / n^3). Furthermore, since you use 10 as a base power (10^-3 = 1 / 10^3 = 0.001), and dcml would have to be severely limited in size for this formula to work *well* (maximum of 18), and is an integer, I would consider other methods than using the power functionality, such as redefinitions.

In other words, in the long run it would be more profitable to rethink your approach.

Measurement is not management.

## RE: compute with decimal number

thanks