Focal Point
[SOLVED]Converting Packed-Decimal to Alphanumeric

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

August 19, 2011, 12:01 PM
dburton
[SOLVED]Converting Packed-Decimal to Alphanumeric
I am trying to convert a packed decimal value of P21.9 to alphanumeric. I have tried using the PTOA function and it gives me a strange output with a bunch of funny characters. Smiler

I tried using the CAR file and just doing a simple FTOA with the DEALER_COST field and it gives me the same output.

 
TABLE FILE CAR
PRINT 
     'CAR.ORIGIN.COUNTRY'
     COMPUTE VAL1/A7 = FTOA(CAR.BODY.DEALER_COST, '(A7)', VAL1);
END


Output

COUNTRY VAL1
ENGLAND ½
ENGLAND ÝÅ
ENGLAND .Í
ENGLAND Ä°
JAPAN „¤
JAPAN Œ¦
ITALY 3³
ITALY ¶
ITALY ¶
ITALY jØ
W GERMANY dz
W GERMANY ¨¶
W GERMANY p·
W GERMANY ˆÃ
W GERMANY |Å
W GERMANY 6À
W GERMANY hÀ
FRANCE ²


Can anyone help me with this? I have no idea why it would be giving me this type of output.

Thanks,

Dave

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


WebFOCUS 7.7.03
Windows Web Server 2008
MS SQL Server 2000
Excel,CSV,PDF,HTML
August 19, 2011, 12:05 PM
Dan Satchell
Use the source format in the function:

TABLE FILE CAR
PRINT 
     'CAR.ORIGIN.COUNTRY'
     COMPUTE VAL1/A7 = FTOA(CAR.BODY.DEALER_COST, '(D7)', VAL1);
END



WebFOCUS 7.7.05
August 19, 2011, 01:36 PM
dburton
Thanks Dan. It is wierd as the Help file for DevStudio says to use the Output format. Maybe I just misunderstood.

Your solution worked. Thanks for the help.

Dave


WebFOCUS 7.7.03
Windows Web Server 2008
MS SQL Server 2000
Excel,CSV,PDF,HTML
August 19, 2011, 02:34 PM
Dan Satchell
The documentation for the FTOA and PTOA is confusing. By output format, they mean any special formatting that you may want to see in the output. In this case, for example, you could put a dollar sign and decimals in the output:

TABLE FILE CAR
PRINT 
     'CAR.ORIGIN.COUNTRY'
     COMPUTE VAL1/A15 = FTOA(CAR.BODY.DEALER_COST, '(D10.2M)', VAL1);
END



WebFOCUS 7.7.05
August 19, 2011, 03:15 PM
dburton
Dan,

I know this question is not related but maybe you can help me out. Once I convert these numbers I then TRIM trailing zeros.

 
DEFINE FILE CAR
VAL1/D12.3=52.000;
END

TABLE FILE CAR
PRINT 
     COMPUTE VAL2/A7 = FTOA(VAL1,'(D12.3)',VAL2);
     COMPUTE VAL3/A7 = TRIM('T',VAL2,25,'0',1,VAL3);
END


This will TRIM trailing zeros but then it leaves a period on the end of the number. I then try to TRIM the period but it doesn't work. I can't use STRREP because then it will take the period out of the string entirely which I don't want to do if the value is something like 1.2

I have also tried STRIP but it will then do the same thing as STRREP without replacing the character.

Any ideas?

Thanks,

Dave


WebFOCUS 7.7.03
Windows Web Server 2008
MS SQL Server 2000
Excel,CSV,PDF,HTML
August 19, 2011, 03:33 PM
Dan Satchell
Why not remove the decimals in the FTOA output format?

DEFINE FILE CAR
 VAL1/D12.3 WITH COUNTRY = 52.000 ;
END

TABLE FILE CAR
 PRINT VAL1
       COMPUTE VAL2/A15 = FTOA(VAL1,'(D12)',VAL2);
END



WebFOCUS 7.7.05
August 19, 2011, 03:46 PM
dburton
I can't remove all the decimals. The values could be 51.204 or 25.000 or any other combination and I need to show the decimal values if they are not all zeros. I figured out a way using an IF statement. Thanks for the help.

Dave


WebFOCUS 7.7.03
Windows Web Server 2008
MS SQL Server 2000
Excel,CSV,PDF,HTML
August 19, 2011, 05:58 PM
Dan Satchell
Here's a link to a previous post that might be helpful:

Removing trailing zeroes after decimal point


WebFOCUS 7.7.05