Focal Point Banner


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.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [CLOSED] Front End Rounding / Rounding Down

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[CLOSED] Front End Rounding / Rounding Down
 Login/Join
 
Platinum Member
posted
Hello, I wanted to know how to round down or front end rounding.


Round to 2 decimals / hundredths

Ex.

IN
4.365375

OUT
4.36

IN
3478.3924635

OUT
3478.39

IN
234.288345

OUT
234.28

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


WebFOCUS 7.6
Windows, All Outputs
 
Posts: 111 | Registered: May 12, 2011Report This Post
Virtuoso
posted Hide Post
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;

NEWVALUE1/I9=INPUT*100;
NEWVALUE2/D14.2=NEWVALUE1/100;

this will however not work if the input fields are to large (above 999.999.999)




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, 2006Report This Post
Virtuoso
posted Hide Post
That's not rounding, that's truncating.
You could use the tandem of converting to alpha (FTOA / PTOA) and back again.


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
 
Posts: 1961 | Location: Netherlands | Registered: September 25, 2007Report This Post
Master
posted Hide Post
Convert to Packed format? /P9.2


WebFOCUS 7.7.05 Windows, Linux, DB2, IBM Lotus Notes, Firebird, Lotus Symphony/OpenOffice. Outputs PDF, Excel 2007 (for OpenOffice integration), WP
 
Posts: 674 | Location: Guelph, Ontario, Canada ... In Focus since 1985 | Registered: September 28, 2010Report This Post
Guru
posted Hide Post
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, 2003Report This Post
Virtuoso
posted Hide Post
According to the first example he wants to truncate.

But if you want to round you can do the same but first add 0.005 to the original value.




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, 2006Report This Post
Expert
posted Hide Post
Frank's suggestion is the best way to deal with this truncation:

-SET &ECHO='ALL';

FILEDEF file1 DISK file1.txt
-RUN

-WRITE FILE1 4.365375
-WRITE FILE1 3478.3924635
-WRITE FILE1 234.288345

FILEDEF MASTER DISK file1.mas
-RUN

-WRITE MASTER FILENAME=FILE1, SUFFIX=FIX
-WRITE MASTER SEGNAME=FILE1
-WRITE MASTER FIELDNAME=AMT1, ALIAS=AMT1, FORMAT=P12.7, ACTUAL=A12, $

TABLE FILE FILE1
PRINT
AMT1
COMPUTE AMT1A/D12.2 = AMT1;
COMPUTE AMT1B/P12.2 = AMT1;
COMPUTE AMT1B/F12.2 = AMT1;

COMPUTE AMT1C1/I8 = AMT1 * 100;
COMPUTE AMT1C2/P10.2 = AMT1C1 / 100;
END
-RUN


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Virtuoso
posted Hide Post
I was looking to create a function for this.
I hope somebody has done that though.

DEFINE FUNCTION ROUND(BASEVALUE,NUMBERS)

To get this dynamical with the field NUMBERS as the variable.




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, 2006Report This Post
Expert
posted Hide Post
Oh Frank,

You know I can never resist a challenge, however small Smiler

A small beginning for you -
-* 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)
  ADJ_BASE/D12.8  = 5 / EXP((LOG(10) * (DECIMALS + 1)), 'D12.8');
  ADJUSTER/D12.8  = IF DIRECTION EQ 'UP' THEN ADJ_BASE ELSE 0 - ADJ_BASE;
  ROUND_IT/D20.8  = BASEVALUE + ADJUSTER;
END

FILEDEF file1 DISK file1.txt
-RUN
-WRITE FILE1 4.365375
-WRITE FILE1 3478.3924635
-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 AMT1/D12.2 = ROUND_IT(AMT, 'UP',  2);
      COMPUTE AMT2/D12.2 = ROUND_IT(AMT, 'DOWN', 2);
      COMPUTE AMT3/P12.2 = ROUND_IT(AMT, 'UP',  2);
      COMPUTE AMT4/P12.2 = ROUND_IT(AMT, 'DOWN', 2);
END

Thanks for your base code Francis, saved a bit of time Smiler

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, 2004Report This Post
Expert
posted Hide Post
Tony, I'm glad you lost your resistance before me! Nice job.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Virtuoso
posted Hide Post
I knew somebody would do it.

thanks a lot on behalf of all the focalpoint users




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, 2006Report This Post
Expert
posted Hide Post
Thanks Guys,

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, 2004Report This Post
Virtuoso
posted Hide Post
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, 2006Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [CLOSED] Front End Rounding / Rounding Down

Copyright © 1996-2020 Information Builders