Focal Point
General NUMBER Format

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/5271076191

October 18, 2006, 05:29 PM
Johnny5
General NUMBER Format
We are trying to get some code written that will let us make the WebFocus code.

I need to do a dynamic calculation that will return either a Count or a Percent. The percent is required to carry 1 decimal and the count 0 decimals. I also need this calculation to be subtotaled via a recompute.

I have looked at the sample code that does this by setting another variable and then doing VAR1/FRM_VAR but I can't duplicate this using the compute and getting my subtotals.

Isn't there a field type that isn't fussy about format that would be equivalent to an Oracle NUMBER field. Why can't I have one decimal in on cell and 8 in another.

Any ideas?


WF 5.3.5 / SOLARS 2.9 / Apache / Tomcat / Oracle (9.2/10g)
October 18, 2006, 06:14 PM
Prarie
Try looking here for some insight to formats
http://documentation.informationbuilders.com/masterinde...13crgt/aafldfrm3.htm


In Focus since 1993. WebFOCUS 7.7.03 Win 2003
I read back through the documentation provided on the link and I understand it. I still have a problem however.

The documenation says that my decimal will show up to as many decimals as it can store. My question is how do I get it to show whatever is stored and not just something in the D12.2 format which will bring everything back to 2 decimals.

What I want is a D12.[variable] or somehow do a
COMPUTE VARIABLE_CALC/D12.[variable] = IF CALC_CD EQ 'PERCENT' THEN (NUMERATOR / DENOMINATOR * 100) (note: rounded to 1 decimal)
ELSE IF CALC_CD = 'COUNT' THEN NUMERATOR (note: rounded to nearest whole number)



WF 5.3.5 / SOLARS 2.9 / Apache / Tomcat / Oracle (9.2/10g)
I did see in the documenation that there is such a thing as Zoned Decimals. It appears that is what is used internally but it doens't seem to be something you can access at run-time unless you are spitting it out to a file as an Alpha.

Is there such a thing that exists that takes any number of variable precision and actually just calls a ROUND function etc.?


WF 5.3.5 / SOLARS 2.9 / Apache / Tomcat / Oracle (9.2/10g)
Hi Johnny5,

I ran a quick search about Zoned Decimals and came across the following which may be of interest:

How to convert alphanumeric to zoned decimal?

Hope it helps. Smiler

Cheers,

Kerry


Kerry Zhan
Focal Point Moderator
Information Builders, Inc.
I don't know if this will help or not... if not, just chunk it.

Anyway... this is a DEFINE FUNCTION I came up with about 4 years ago to do arbitrary precision before WF had the decimal alignment feature.

The output is an A30 field, but it give you the ability to specify ARBITRARY PRECISION with MINIMUM PRECISION define on your output format.

For example:

Assume you needed to always have a minimum of 3 decimal places displayed, but you also need to retain FULL precision for values that have more than 3 decimal places.

COMPUTE NEWFIELD/A30=PRECISN(NUMBER,'(D18.6B)',x);
  
INPUT         Value of 'x'     OUTPUT
20.0097         3              20.0097
20.0            2              20.00
20.0097000      4              20.0097


DEFINE FUNCTION PRECISN (VAL/D20,FMT/A9,SIGNIF/D2)
-* Convert value to Alpha and left justify
  VAL1/A30=TRIM('L',FTOA(VAL,FMT,'A30'),30,' ',1,'A30');
-* Find the first ')' or space (due to memory not being cleared
-* between function calls).
  POS0/I2     =IF (VAL1 CONTAINS '(')
                 THEN
                   POSIT(VAL1,30,')',1,'I2')
                 ELSE
                   POSIT(VAL1,30,' ',1,'I2') - 1;
-* Substring up to POS0 to get our value to work with.
  VAL2/A30=IF (VAL1 CONTAINS '(')
                 THEN
                   SUBSTR(30,VAL1,1,POS0,30,'A30')
                 ELSE
                   SUBSTR(30,VAL1,1,POS0,30,'A30');
-* Find the first '.'
  POS1/I2     =POSIT(VAL1,30,'.',1,'I2') + 1 + SIGNIF;
-* Get the length of the string
  LEN1/I2     =ARGLEN(30,VAL2,'I2');
-* Pull off the last part of the number
-* after the '.' and after the specified significant number of digits.
  LASTPART/A30=IF (VAL2 CONTAINS '(')
                 THEN
                   SUBSTR(30,VAL2,POS1,LEN1 - 1,30,'A30')
                 ELSE
                   SUBSTR(30,VAL2,POS1,LEN1,30,'A30');
-* Trim any zero's at the end of the non-significant digits
  TRIM1/A30 =TRIM('T',LASTPART,30,'0',1,'A30');
-* Create value which will remove the '.' if SIGNIF is 0 and everything right
-* of the decimal is 0.
  RMDEC/I1=IF (SIGNIF EQ 0) AND (TRIM1 EQ ' ') THEN -1 ELSE 0;
-* Put the number back together, include trailing ')' if negative.
  TEMP1/A80   =IF (VAL2 CONTAINS '(') 
                 THEN
                   SUBSTR(30,VAL2,1,POS1 - 1 + RMDEC,30,'A30') ||
                   (TRIM1 || ')')
                 ELSE
                   SUBSTR(30,VAL2,1,POS1 - 1 + RMDEC,30,'A30') ||
                   TRIM1;
-* Output the value.
  PRECISN/A30=SUBSTR(80,TEMP1,1,30,30,'A30');
END