Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SUM VARIABLES WIDTH DECIMALS 1

Status
Not open for further replies.

frask

Programmer
Aug 31, 2005
5
ES
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
 
To anyone who can be interested:

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);
 
Right idea, but not quite there in implementation.

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:
-SET &RE = FTOA(15.25 - 7.39 , '(D15.2c)', 'A15');

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 = LJUST(15,&RE,'A15');
-SET &RE = TRUNCATE(&RE);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top