×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

SUM VARIABLES WIDTH DECIMALS

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

RE: SUM VARIABLES WIDTH DECIMALS

Amper variables are limited to integer or character data.

RE: SUM VARIABLES WIDTH DECIMALS

(OP)
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);

RE: SUM VARIABLES WIDTH DECIMALS

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);

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close