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.
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
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
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
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, 2004
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
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, 2004
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
Perhaps we should take your question non-literally?
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, 2004
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 ...
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
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 ....