October 19, 2006, 01:05 PM
Johnny5I 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)
October 20, 2006, 01:50 PM
Johnny5I 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.?
October 27, 2006, 04:48 PM
KerryHi 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.
Cheers,
Kerry
October 27, 2006, 07:10 PM
Bernie OttI 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