As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.
Join the TIBCO Community TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.
From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
Request access to the private WebFOCUS User Group (login required) to network with fellow members.
Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.
What I see is not the correct way of rounding. That would sometimes give little higher output.
waht You can do is first compute the input field by multiplying it with 100 and then make it to an integer. In the nextstep you devide it again by 100;
Consider using half adjust and truncate routine; in this case add .005 to positive numbers and -0.005 to negative numbers and then truncate to two decimal places.
jimster06 DevStu WF 7.6.11 W7 HTML, PDF, EXL2K
Posts: 252 | Location: USA | Registered: April 15, 2003
I thought that I ought to mention that the use of D12.8 "restricts" the decimal places to 7 which should be good for most apps. Well that's the theory of course.
If anyone is puzzling over what the "5 / EXP((LOG(10) * (DECIMALS + 1))" achieves - LOG(10) = gives the natural log of 10 multiplying this by the number of decimal places required and then inversing the natural log (using EXP) give values of 10 for decimals = 0, 100 for decimals = 1, 1000 for decimals = 2 etc. by dividing 5 by this value we achieve respective values of .5, .05 and .005. Up or Down will negate this value as necessary before adding it to the original number to give your "rounded" result.
Things to note are - no validation is actioned upon the inputs into the function, nor is the output really rounded as you might think (double precision at work!)
So use with a little understanding and care.
Yet another one to put into the FUNCTION bank.
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
Posts: 5694 | Location: United Kingdom | Registered: April 08, 2004
here is an other solution for the rounding function
-* File functions.fex
-* Rounding function
-* Basevalue : value to be rounded;
-* Direction : round up or round down;
-* Decimals : number of decimal places to round to;
DEFINE FUNCTION ROUND_IT(BASEVALUE/D20.6, DIRECTION/A4, DECIMALS/I2)
CORRECTOR/D7.0= 10**(-DECIMALS);
-* raising 10 to the power of the number of decimals
ADJ_BASE/D12.8= CORRECTOR/2;
-* to calculate the amount you want to add or subtract
ADJUSTER/D12.8 = IF DIRECTION EQ 'UP' THEN ADJ_BASE ELSE 0 - ADJ_BASE;
NEWBASE/D20.8= IF BASEVALUE LT 0 THEN BASEVALUE - ADJUSTER ELSE BASEVALUE+ADJUSTER ;
-* newbase is the adjusted base for rounding
ROUND_ON/D20.8= INT(NEWBASE/CORRECTOR);
-* devide the newbase with the corrector pe 3478.3964 + 0.005 with 10^-2 gives 347840.14 integer is 347840
ROUND_IT/D20.8=ROUND_ON*CORRECTOR;
-* integer multiplied with the 10^-2 is 3478.40
END
FILEDEF file1 DISK file1.txt
-RUN
-WRITE FILE1 4.365375
-WRITE FILE1 3478.3964635
-WRITE FILE1 -475.7924311
-WRITE FILE1 234.288345
-WRITE FILE1 -234.288345
FILEDEF MASTER DISK file1.mas
-RUN
-WRITE MASTER FILENAME=FILE1, SUFFIX=FIX
-WRITE MASTER SEGNAME=FILE1
-WRITE MASTER FIELDNAME=AMT, ALIAS=AMT, FORMAT=P12.7, ACTUAL=A12, $
TABLE FILE FILE1
PRINT AMT
COMPUTE AMT0/D12.5 = ROUND_IT(AMT, 'UP', 4);
COMPUTE AMT1/D12.5 = ROUND_IT(AMT, 'UP', 3);
COMPUTE AMT2/D12.5 = ROUND_IT(AMT, 'UP', 2);
COMPUTE AMT3/P12.5 = ROUND_IT(AMT, 'UP', 1);
COMPUTE AMT0/P12.5 = ROUND_IT(AMT, 'UP', 0);
COMPUTE AMT4/P12.5 = ROUND_IT(AMT, 'UP', -1);
COMPUTE AMT5/P12.5= ROUND_IT(AMT, 'UP', -2);
COMPUTE AMT6/P12.5 = ROUND_IT(AMT, 'UP', -3);
END
This one does the same as the round function in Excel, in fact the DIRECTION (UP or DOWN) is an strange part in it. Rounding is always up if the figure is 5 or higher.
The difference with Tony's solution is that in this case the hidden result is also as it should be.
Frank
prod: WF 7.6.10 platform Windows, databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7 test: WF 7.6.10 on the same platform and databases,IE7
Posts: 2387 | Location: Amsterdam, the Netherlands | Registered: December 03, 2006