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     [SOLVED] Removing Trailing Zeros

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED] Removing Trailing Zeros
 Login/Join
 
Master
posted
We have data we pull from HIVE, which is obviously an ASCII column.. Data is represented as 0.0350000. We do the following, but it leaves trailing zeros 3.500000%, which all we are looking for is 3.5%. However, as I was creating this demo, the below code doesn't seem to work at all, which only adds to my confusion. It always comes back as zero. What am I missing below and how can I remove trailing zeros?


-SET &MYPERC = '0.0350000';
-SET &MYPERC = (ATODBL(&MYPERC, '255', 'D11.6%') * 100);
-TYPE MYPERC = &MYPERC

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



- FOCUS Man, just FOCUS!
-----------------------------
Product: WebFOCUS
Version: 8.1.04
Server: Windows 2008 Server
 
Posts: 578 | Registered: October 01, 2014Report This Post
Expert
posted Hide Post
Do you need to do this in Dialogue manager or WebFOCUS TABLE FILE? There are different solutions depending on where you need to do it.


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
Master
posted Hide Post
The code we are working with is from a WebFOCUS TABLE FILE..


TABLE FILE AAA/PROC_NAME
PRINT
COMPUTE ASOFDATE/A10 = '&ASOFDATE';
COMPUTE ANNUALINTERESTRATEfmt/A25V = FPRINT(ATODBL(PROC_NAME.RESPONSE.ANNUALINTERESTRATE, '255', 'D11.6%') * 100, 'D11.6%', 'A25V');
...
...



- FOCUS Man, just FOCUS!
-----------------------------
Product: WebFOCUS
Version: 8.1.04
Server: Windows 2008 Server
 
Posts: 578 | Registered: October 01, 2014Report This Post
Expert
posted Hide Post
In Dialogue Manager, you need to set the numeric precision - in this example, it is set to 1 decimal place::

SET DMPRECISION = 1
-RUN

-SET &MYPERC = 0.0350000;
-SET &MYPERC = &MYPERC * 100;
-TYPE MYPERC = &MYPERC


If you need a variable number of decimal places, that might be possible using some other technique.


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
Master
posted Hide Post
Thanks,

In Dialog Manager, I was trying to represent the ASCII portion, being converted as needed from the TABLE, which is why I wrapped it in single quotes. I'm guessing ATODBL() doesn't work in Dialog Manager.

But WebFOCUS TABLE FILE is where I really need a answer for.



- FOCUS Man, just FOCUS!
-----------------------------
Product: WebFOCUS
Version: 8.1.04
Server: Windows 2008 Server
 
Posts: 578 | Registered: October 01, 2014Report This Post
Master
posted Hide Post
quote:
how can I remove trailing zeros?

-SET &MYPERC = '0.0350000';
-SET &MYPERC = TRIM('T', &MYPERC, &MYPERC.LENGTH, '0', 1, A&MYPERC.LENGTH); 
-TYPE MYPERC = &MYPERC
-EXIT  

Gives:
MYPERC = 0.035 
 
Posts: 822 | Registered: April 23, 2003Report This Post
Master
posted Hide Post
I tried the following and got the something closer.. Zeros are gone, but the '.' is at the end..

COMPUTE ANNUALINTERESTRATE2fmt/A25V = TRIM('T', FPRINT(ATODBL(PROC_NAME.RESPONSE.ANNUALINTERESTRATE, '255', 'D11.6%') * 100, 'D11.6%', 'A25V'), 11, '0', 1, 'A255V');


EDIT: Only for the whole %, it shows a decimal on the end. The rest, like 3.75 come out perfectly.

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



- FOCUS Man, just FOCUS!
-----------------------------
Product: WebFOCUS
Version: 8.1.04
Server: Windows 2008 Server
 
Posts: 578 | Registered: October 01, 2014Report This Post
Expert
posted Hide Post
How about not using TRIM, but specifying 'D11.2%'?


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
Master
posted Hide Post
This is for bank loans and they go to 6 decimals. I only wish.. :P



- FOCUS Man, just FOCUS!
-----------------------------
Product: WebFOCUS
Version: 8.1.04
Server: Windows 2008 Server
 
Posts: 578 | Registered: October 01, 2014Report This Post
Expert
posted Hide Post
The answer is here: [NFR?] Surpress Trailing Zeros


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
Master
posted Hide Post
Francis, in addition to your excellent IT/Developer skills, you are also a fantastic researcher/searcher. Smiler
 
Posts: 822 | Registered: April 23, 2003Report This Post
Expert
posted Hide Post
In the post to which Francis' refers, there is a suggestion of using a FUNCTION which, as you may use it many times, is an excellent idea here.

As you are looking for a percentage value with the %sign suffixed to the "trimmed" result(?), try this code -
DEFINE FUNCTION REMTRAIL(DBLPREC/D12.6%)
  F_FPRINT/A25 = FPRINT(DBLPREC, 'D12.6%', 'A25');
-* By specifying only 24 chars of output we drop the %sign off
  F_RJUST/A25  = RJUST(25, F_FPRINT, 'A24');
-* Now we force a hard concatenation of the %sign
  REMTRAIL/A25V = TRIM('T', F_RJUST, 24, '0', 1, REMTRAIL)||'%';
END
-RUN

Also, do not forget to SET CENT-ZERO = ON if you want the leading zero if the value is less than 0 e.g. 0.03% instead of .03%

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,



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
Expert
posted Hide Post
Thanks Francis, but I was only taking David Briars' code and placing it into a FUNCTION - which we so often forget that we can do.

I remember back in the day when we would have done the unmentionable for an easy method of creating UWS!

T
 
Posts: 5694 | Location: United Kingdom | Registered: April 08, 2004Report This Post
Expert
posted Hide Post
David, yes I found your excellent solution and thanks to Tony for simply turning it into a function that we should all copy.


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
Master
posted Hide Post
Sorry, I've been out of pocket, but I'll give the function a try today..

Thanks



- FOCUS Man, just FOCUS!
-----------------------------
Product: WebFOCUS
Version: 8.1.04
Server: Windows 2008 Server
 
Posts: 578 | Registered: October 01, 2014Report This Post
Master
posted Hide Post
I tried your function, but it seemed to do nothing, but add the % on the end and pad a bunch of spaces to the beginning..

-DEFAULTH &MyVAR = 0.356451;

DEFINE FUNCTION REMTRAIL(DBLPREC/D12.6%)
-* SET CENT-ZERO = ON -*if you want the leading zero if the value is less than 0 e.g. 0.03% instead of .03%
  F_FPRINT/A25 = FPRINT(DBLPREC, 'D12.6%', 'A25');
-* By specifying only 24 chars of output we drop the %sign off
  F_RJUST/A25  = RJUST(25, F_FPRINT, 'A24');
-* Now we force a hard concatenation of the %sign
  REMTRAIL/A25V = TRIM('T', F_RJUST, 24, '0', 1, REMTRAIL)||'%';
END
-RUN

-SET &MyVAR2 = REMTRAIL(&MyVAR);
-TYPE MyVAR2 = &MyVAR2;


Results:
MyVAR2 =                  .356451%;



- FOCUS Man, just FOCUS!
-----------------------------
Product: WebFOCUS
Version: 8.1.04
Server: Windows 2008 Server
 
Posts: 578 | Registered: October 01, 2014Report This Post
Expert
posted Hide Post
Well, there are no trailing zeroes in the Dialogue Manager variable &MyVAR and you stated you need this for TABLE FILE.


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
Expert
posted Hide Post
You beat me to it Francis!

DEFINE FUNCTION REMTRAIL(DBLPREC/D12.6%)
-* SET CENT-ZERO = ON -*if you want the leading zero if the value is less than 0 e.g. 0.03% instead of .03%
  F_FPRINT/A25 = FPRINT(DBLPREC, 'D12.6%', 'A25');
-* By specifying only 24 chars of output we drop the %sign off
  F_RJUST/A25  = RJUST(25, F_FPRINT, 'A24');
-* Now we force a hard concatenation of the %sign
  REMTRAIL/A25V = TRIM('T', F_RJUST, 24, '0', 1, REMTRAIL)||'%';
END
-RUN

DEFINE FILE GGSALES
 D_PERCENT/D12.6 = DECODE SEQ_NO (1     6.21118
                                  2    12.42
                                  3     5.0000000
                                  4     1.01
                                  5 12345.012 ELSE 0);
END
TABLE FILE GGSALES
PRINT SEQ_NO
      D_PERCENT
      COMPUTE C_PERCENT/A25V = REMTRAIL(D_PERCENT);
IF SEQ_NO FROM 1 TO 5
ON TABLE SET ONLINE-FMT STANDARD
END
-EXIT

Giving

  Sequence#      D_PERCENT  C_PERCENT
  ---------      ---------  ---------
          1       6.211180                  6.21118%
          2      12.420000                 12.42%
          3       5.000000                  5.%
          4       1.010000                  1.01%
          5  12,345.012000             12,345.012%


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
Master
posted Hide Post
Tony, you still show the same problem I'm already having.. Look at your results. 5.00000 turns into 5.%

I had gotten this to work, but with the same issue.
COMPUTE ANNUALINTERESTRATE2fmt/A25V = TRIM('T', FPRINT(ATODBL(PROC_NAME.RESPONSE.ANNUALINTERESTRATE, '255', 'D11.6%') * 100, 'D11.6%', 'A25V'), 11, '0', 1, 'A255V');



- FOCUS Man, just FOCUS!
-----------------------------
Product: WebFOCUS
Version: 8.1.04
Server: Windows 2008 Server
 
Posts: 578 | Registered: October 01, 2014Report This Post
Expert
posted Hide Post
quote:
Removing Trailing Zeros

Perhaps we should take your question non-literally? Wink

In that case then I would add a section to the function to check if there are any characters after the decimal point and add a zero before the percentage sign.

DEFINE FUNCTION REMTRAIL(DBLPREC/D12.6%)
  F_FPRINT/A25 = FPRINT(DBLPREC, 'D12.6%', 'A25');
-* By specifying only 24 chars of output we drop the %sign off
  F_RJUST/A25V = TRIM('T', RJUST(25, F_FPRINT, 'A24'), 24, '0', 1, F_RJUST);
-* Check for no decimals
  F_DECIMALS/A25V = GETTOK(F_RJUST, 25, -1, '.', 25, 'A25');
-* ... and assign the string to be appended
  F_APPEND/A2 = IF F_DECIMALS NE '' THEN '%' ELSE '0%';
-* Now we force a hard concatenation of the %sign
  REMTRAIL/A25V = F_RJUST||F_APPEND;
END
-RUN

DEFINE FILE GGSALES
 D_PERCENT/D12.6 = DECODE SEQ_NO (1     6.21118
                                  2    12.42
                                  3     5.0000000
                                  4     1.01
                                  5 12345.012 ELSE 0);
END
TABLE FILE GGSALES
PRINT SEQ_NO
      D_PERCENT
      COMPUTE C_PERCENT/A25V = REMTRAIL(D_PERCENT);
IF SEQ_NO FROM 1 TO 5
ON TABLE SET ONLINE-FMT STANDARD
END
-EXIT


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
Master
posted Hide Post
Ha.. Well, that's one way, but my requirements are to strip it to 5% or 3.75%. I'll figure it out, this gets me on track..

Thanks



- FOCUS Man, just FOCUS!
-----------------------------
Product: WebFOCUS
Version: 8.1.04
Server: Windows 2008 Server
 
Posts: 578 | Registered: October 01, 2014Report This Post
Master
posted Hide Post
Good grief. Are people really that picky !! ?? The only way you are going to make this work the way you want is to a) strip out all the trailing zeros and replace them with blanks, convert it all to alpha, then if the last character is a period strip that out too,add a percent sign at the end, figure out the maximum number of characters you will have, pad each value with blanks individually such that tey each have the same length and then right-justify the whole mess.

Or you could just tell your boss that life is too short ...


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
Master
posted Hide Post
I don't know if I would call that a picky boss. I would most likely call it a limitation of the Focus language. In most other languages, this is a one liner.



- FOCUS Man, just FOCUS!
-----------------------------
Product: WebFOCUS
Version: 8.1.04
Server: Windows 2008 Server
 
Posts: 578 | Registered: October 01, 2014Report This Post
Master
posted Hide Post
Smiler Could you show me how it could be done in a one liner in another language, let's say C, or javascript?

Really what it amounts to is that you want it to display as an integer if it is a round number and a floating point if it isn't, with the added complication that the decimal points have to line up and trailing zeros eliminated. That's a lot of work for one line of code ....


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
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Removing Trailing Zeros

Copyright © 1996-2020 Information Builders