## SUM VARIABLES WIDTH DECIMALS

## SUM VARIABLES WIDTH DECIMALS

(OP)

Hellow.

I try to sum some numeric variables which can have decimals or not. The problem is that webfocus doesnÂ´ t sum the decimal part. Example;

-SET &A = 8000;

-SET &B = 1.1;

-SET &C= &A + &B;

An the results are:

&C = 8001; instead of 8001.1

Can someone help me?

Thanks

I try to sum some numeric variables which can have decimals or not. The problem is that webfocus doesnÂ´ t sum the decimal part. Example;

-SET &A = 8000;

-SET &B = 1.1;

-SET &C= &A + &B;

An the results are:

&C = 8001; instead of 8001.1

Can someone help me?

Thanks

## RE: SUM VARIABLES WIDTH DECIMALS

## RE: SUM VARIABLES WIDTH DECIMALS

You can avoid lossing decimals by converting the results to alphanumeric with the function FTOA:

-SET &OP = 15.25 - 7.39 ;

-SET &RE = FTOA(&OP.EVAL, '(D15.2)', A15);

## RE: SUM VARIABLES WIDTH DECIMALS

ALL values in the Dialogue Manager are stored as character strings. This is fine for alphanumerics and whole numbers, but HOW MANY decimal point digits should be stored?

So, what happens is, when a calculation is done, the strings involved are converted to double precision, the calculation done, and then the result converted back to INTEGER (since we don't know how many decimal digits to keep), and then converted to alpha. What you can do is 'catch' the result BEFORE it gets converted to integer, and convert it yourself, providing information on the number of decimal digits desired. You do this (as stated), by using the FTOA routine, BUT, you must do the calculation WITHIN the subroutine, to KEEP the decimal digits. So, it looks like this:

## CODE

What's different is:

1. the calculation is done within the subroutine itself

2. the output format (which specifies number of decimal digits) has the 'c' edit option, which suppresses the commas you NORMALLY get with 'D' format output.

3. The last argument is enclosed in single quotes. The length should be the same (or more) than that given in the format.

The result will have leading blanks, which, if not desired, can be removed by using the LJUST routine and the TRUNCATE function, like this:

## CODE

-SET &RE = TRUNCATE(&RE);