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] Keeping a formatted value for use in a compute

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED] Keeping a formatted value for use in a compute
 Login/Join
 
Silver Member
posted
Code snippet

TABLE FILE DETAIL
SUM
COMPUTE AVGDispatchesPerTrailer/D12.2=DispatchesPerTrailer/13;
COMPUTE PCTCHG/D8.2%=( &CURRENTDISPATCHESPERTRAILER - AVGDispatchesPerTrailer ) / AVGDispatchesPerTrailer * 100;
ON TABLE HOLD AS AVGDATA

&CURRENTDISPATCHESPERTRAILER = 2.45
AVGDispatchesPerTrailer = 2.38
PCTCHG = 2.94

I am having a problem with PCTCHG. This is what I want...
PCTCHG = (2.45 - 2.38) / 2.38 * 100 = 2.94

This is what is happening...
PCTCHG = (2.45 - 2.38391) / 2.38391 * 100 = 2.77

DispatchesPerTrailer/13 = 2.38391 which I format to 2 decimal places

When I compute PCTCHG, I want to use that number with only 2 decimals, but it remains at 5.
How can I get AVGDispatchesPerTrailer to equal 2.38?

This message has been edited. Last edited by: David M,


WebFOCUS 8.1.05M, 8.2.02M
Windows, All Outputs
 
Posts: 34 | Location: Southern New Jersey | Registered: January 24, 2017Report This Post
Gold member
posted Hide Post
Use AVGDispatchesPerTrailer/D12.2=DispatchesPerTrailer/13; in a DEFINE instead of COMPUTE.

Something like this.

 
DEFINE FILE DETAIL
AVGDispatchesPerTrailer/D12.2 = DispatchesPerTrailer/13;
END

TABLE FILE DETAIL
SUM
COMPUTE PCTCHG/D8.2%=( &CURRENTDISPATCHESPERTRAILER - AVGDispatchesPerTrailer ) / AVGDispatchesPerTrailer * 100; 
ON TABLE HOLD AS AVGDATA


Tharun Katanguru
SBOX- 8205 DEV/TEST/PROD : 8105 8205
Linux, All Outputs
 
Posts: 52 | Location: BOWL OF PASTA | Registered: October 13, 2016Report This Post
Silver Member
posted Hide Post
Thanks tomatosauce for your quick response, but I am still getting PCTCHG = 2.77

Does the statement..
AVGDispatchesPerTrailer/D12.2=DispatchesPerTrailer/13;
simply display AVGDispatchesPerTrailer as 2 decimals or does it convert it?


WebFOCUS 8.1.05M, 8.2.02M
Windows, All Outputs
 
Posts: 34 | Location: Southern New Jersey | Registered: January 24, 2017Report This Post
Expert
posted Hide Post
It displays 2 decimals but retains the full value. Try using P8.2.

From the docs:

Describing Data With WebFOCUS Language > Describing an Individual Field > The Displayed Data Type: USAGE > Numeric Display Options > Rounding

quote:
The details of rounding are handled in the following ways for the following numeric formats:

Integer format When a value with decimal places is assigned to an integer field, the value is rounded before it is stored. If the value is assigned using a DEFINE or COMPUTE command, the decimal portion of the value is truncated before it is stored.

Packed-decimal format When a value is assigned to a packed-decimal field, and the value has more decimal places than the field format specifies, the value is rounded before it is stored.

Floating-point single-precision and double-precision formats When a value is assigned to one of these fields, and the value has more decimal places than the field format specifies, the full value is stored in the field (up to the limit of precision determined by the field internal storage type). When this value is later displayed, however, it is rounded.

Note that if the decimal portion of a floating-point value as it is internally represented in hexadecimal floating-point notation is repeating (that is, non-terminating), the repeating hexadecimal number is resolved as a non-repeating slightly lower number, and this lower number is stored as the field value. In these situations, if in the original value of the digit to be rounded had been a five (which would be rounded up), in the stored lower value, it would become a four (which is rounded down).



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
Your issue may probably be somewhere else than changing the COMPUTE to a DEFINE.

Look at this sample where I kept 5 decimals and my result only have 2 no matter if I use DEFINE or COMPUTE:
-SET &VAR = 2.45;
DEFINE FILE CAR
RCST1/P12.5 = RETAIL_COST / 1500;
END
TABLE FILE CAR
SUM RCST1
    COMPUTE RCST2 /P12.5 = RETAIL_COST / 1500;
    COMPUTE AVG1  /P12.2 = (&VAR - RCST1) / RCST1 * 100;
    COMPUTE AVG2  /P12.2 = (&VAR - RCST2) / RCST2 * 100;
BY COUNTRY
BY CAR
END


Post your whole code.

Using /D instead of /P have same result. It depends on the input field as Francis refer and more a question of rounding function.


WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007
 
Posts: 2409 | Location: Montreal Area, Qc, CA | Registered: September 25, 2013Report This Post
Silver Member
posted Hide Post
Thanks Francis, worked perfectly!
And thanks for the doc reference.

David M.


WebFOCUS 8.1.05M, 8.2.02M
Windows, All Outputs
 
Posts: 34 | Location: Southern New Jersey | Registered: January 24, 2017Report 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] Keeping a formatted value for use in a compute

Copyright © 1996-2020 Information Builders