Focal Point
SOLVED - SET Variable Format Question

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/440104025

September 02, 2010, 11:19 AM
ColdWhiteMilk
SOLVED - SET Variable Format Question
I have a series of -SET variables that I'm trying to assign the format to:

-SET &TOTAL01= &RECORDS;
-SET &TOTAL01PCT= &RECORDS * .90;
-SET &TOTAL02PCT= &RECORDS * .10;


I noticed that when the value for &TOTAL01 is equal to 181, that the value of &TOTAL01PCT is 162, and the value of &TOTAL02PCT is 18. This does not total the original 181.

I think the problem is that 181 * .90 is actually 162.9, but the SET variable is actually returning 162.

Is there a way to apply formatting to the SET variable so that this will round correctly?

This message has been edited. Last edited by: ColdWhiteMilk,


Production - 7.6.4
Sandbox - 7.6.4
September 02, 2010, 11:30 AM
fatboyjim
Hi,

You can use the DMPRECISION setting before the calculation and to whatever the precision is.

  
SET DMPRECISION = 2
-RUN


Best Regards,

Jimmy Pang


DEV: WF 7.6.10
TEST: WF 7.6.10
PROD: WF 7.6.10
MRE: WF 7.6.4
OS/Platform: Windows
Dev Studio: WF 7.7
Output: HTML, EXCEL, PDF, GRAPH, LOTUS, CSV
September 02, 2010, 11:42 AM
Tom Flynn
quote:
SET DMPRECISION = 2
-RUN


Doesn't work for DM commands, this does:

  
-SET &TOTAL01   = 181;
-SET &TOTAL01PCT= (&TOTAL01 * .90) * 100;
-SET &TOTAL02PCT= (&TOTAL01 * .10) * 100;
-SET &TOTAL01_PCT = IF &TOTAL01PCT.LENGTH EQ 5 THEN EDIT(&TOTAL01PCT,'999.9') ELSE
-                   IF &TOTAL01PCT.LENGTH EQ 4 THEN EDIT(&TOTAL01PCT,'99.9')  ELSE
-                   IF &TOTAL01PCT.LENGTH EQ 3 THEN EDIT(&TOTAL01PCT,'9.9')   ELSE EDIT(&TOTAL01PCT,'.9');
-SET &TOTAL02_PCT = IF &TOTAL02PCT.LENGTH EQ 5 THEN EDIT(&TOTAL02PCT,'999.9') ELSE
-                   IF &TOTAL02PCT.LENGTH EQ 4 THEN EDIT(&TOTAL02PCT,'99.9')  ELSE
-                   IF &TOTAL02PCT.LENGTH EQ 3 THEN EDIT(&TOTAL02PCT,'9.9')   ELSE EDIT(&TOTAL01PCT,'.9');

-TYPE &TOTAL01_PCT
-TYPE &TOTAL02_PCT
-EXIT



Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
September 02, 2010, 11:58 AM
Tony A
quote:
Doesn't work for DM commands

??????

Then why does this -
SET DMPRECISION = 2
-RUN
-SET &TOTAL01   = 181;
-SET &TOTAL01PCT= &TOTAL01 * 0.90;
-SET &TOTAL02PCT= &TOTAL01 * 0.10;
-? &TOTAL

give this
 CURRENTLY DEFINED & VARIABLES STARTING WITH 'TOTAL':
 &TOTAL01      = 181
 &TOTAL01PCT   = 162.9
 &TOTAL02PCT   = 18.1

If the requirement is to have "correctly" rounded integers then I would be inclined to force the rounding and go with this -
-SET &TOTAL01   = 181;
-SET &TOTAL01PCT= (&TOTAL01 * 0.90) + 0.5;
-SET &TOTAL02PCT= (&TOTAL01 * 0.10) + 0.5;
-? &TOTAL

Don't forget that if you used a multiplier of .5 in this example then you would get 91 and 91 so you need to know the data you are handling and code accordingly.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
September 02, 2010, 11:59 AM
fatboyjim
Hi,

Seems to work for me

  

-SET &TOTAL01   = 181; 
-SET &TOTAL01PCT= &TOTAL01 * .90;
-TYPE &TOTAL01PCT

SET DMPRECISION = 2
-RUN

-SET &TOTAL01PCT= &TOTAL01 * .90;
-TYPE &TOTAL01PCT



My output is
162
162.9

The first output is before the DMPRECISION is set (default is OFF)

Bst Regards,

Jimmy Pang


DEV: WF 7.6.10
TEST: WF 7.6.10
PROD: WF 7.6.10
MRE: WF 7.6.4
OS/Platform: Windows
Dev Studio: WF 7.7
Output: HTML, EXCEL, PDF, GRAPH, LOTUS, CSV
September 02, 2010, 12:05 PM
Tom Flynn
Jimmy,

You are absolutely correct. I used it above the 1st -SET, not the 2nd. Much cleaner/easier!!

Thanks!


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
September 02, 2010, 01:26 PM
ColdWhiteMilk
What if I want the 162.9 to round up to 163?


Production - 7.6.4
Sandbox - 7.6.4
September 02, 2010, 01:41 PM
fatboyjim
Hi,

You can try DMPRECISION = 0

Best Regards,

Jimmy Pang


DEV: WF 7.6.10
TEST: WF 7.6.10
PROD: WF 7.6.10
MRE: WF 7.6.4
OS/Platform: Windows
Dev Studio: WF 7.7
Output: HTML, EXCEL, PDF, GRAPH, LOTUS, CSV
September 02, 2010, 02:35 PM
ColdWhiteMilk
Thank you. This appears to be working.

You all are the best!


Production - 7.6.4
Sandbox - 7.6.4