Focal Point
[SOLVED] DOUBLE TO ALPHANUMERIC

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

December 03, 2015, 03:29 PM
FernB.
[SOLVED] DOUBLE TO ALPHANUMERIC
Hello all,

An alphanumeric field in my report was outputting for example, "945.5, 784.33, 1054.006". I need to set it to where all data is locked with three decimal places (i.e. "945.500, 784.330, 1054.006").

The way I am attempting to do this is to convert the field to DOUBLE with the set decimal places, and then convert back to ALPHANUMERIC. I have successfully converted the field to DOUBLE (using ATODBL )but I am having trouble converting back to ALPHA.

I appreciate all suggestions.

This message has been edited. Last edited by: <Emily McAllister>,


WebFOCUS 8
Windows, All Outputs
December 03, 2015, 04:02 PM
Francis Mariani
Unfortunately I don't think there's a WF field format to output trailing zeros.

I assume you have ONE alphanumeric field that contains THREE numeric values.

Here's a method of doing it without converting to a numeric format. It involves right-justifying the individual values to have a predictable decimal point position, then adding the appropriate number of zeros:

TABLE FILE CAR
PRINT
COMPUTE AN/A30 = '945.5, 784.33, 1054.006';

COMPUTE AN1/A30 = RJUST(30, GETTOK(AN, 30, 1, ',', 30, 'A30'), 'A30'); NOPRINT
COMPUTE AN2/A30 = RJUST(30, GETTOK(AN, 30, 2, ',', 30, 'A30'), 'A30'); NOPRINT
COMPUTE AN3/A30 = RJUST(30, GETTOK(AN, 30, 3, ',', 30, 'A30'), 'A30'); NOPRINT

COMPUTE AN1E/A40 = IF SUBSTR(30, AN1, 29, 30, 1, 'A1') EQ '.' THEN AN1 || '00' 
              ELSE IF SUBSTR(30, AN1, 28, 30, 1, 'A1') EQ '.' THEN AN1 || '0' ELSE AN1; NOPRINT
COMPUTE AN2E/A40 = IF SUBSTR(30, AN2, 29, 30, 1, 'A1') EQ '.' THEN AN2 || '00' 
              ELSE IF SUBSTR(30, AN2, 28, 30, 1, 'A1') EQ '.' THEN AN2 || '0' ELSE AN2; NOPRINT
COMPUTE AN3E/A40 = IF SUBSTR(30, AN3, 29, 30, 1, 'A1') EQ '.' THEN AN3 || '00' 
              ELSE IF SUBSTR(30, AN3, 28, 30, 1, 'A1') EQ '.' THEN AN3 || '0' ELSE AN3; NOPRINT

COMPUTE ANE/A130 = AN1E || ',' || (' ' | AN2E) || ',' || (' ' | AN3E);
BY LOWEST 1 COUNTRY
END



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
December 03, 2015, 05:01 PM
FernB.
Yes, sorry for not being specific enough. It is only one field and the example values (945.5, 784.33, 1054.006) would be separate values.

A coworker of mine found the solution to convert the original field A6 (alphanumeric) to DOUBLE D9.3 and use FTOA to return the values as A10. It works and thank you for your contribution as well.


WebFOCUS 8
Windows, All Outputs
December 03, 2015, 07:32 PM
susannah
Look up the FPRINT function. it can take a funky value with commas and decimals and return a nice character string.
Is that what you're tryng to do?




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID