Focal Point
[SOLVED]Converting a decimal number to alpha

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

July 29, 2016, 09:05 AM
Trudy
[SOLVED]Converting a decimal number to alpha
I want to convert a D20.2 field to alpha. This is a GPA value so always has the #.## format. I was wondering if this could be done in a DEFINE or a COMPUTE? I can do it in the master using the following expression but want to know if there is a better/more efficient way to do it, either in the master or using DEFINE's or COMPUTE's?

  
SUBSTRING(FPRINT(SYVSTAI_CUMULATIVE_GPA,'D20.2','A25'), 22, 4)


Thanks

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


WF8
Windows
July 29, 2016, 09:51 AM
BabakNYC
Two ways you can do this, either use EDIT (it will zero fill the output) or use PTOA function.
DEFINE FILE ibisamp/car
 NEW_FIELD/A20=EDIT ( RCOST );
 PTOA_FLD/A20=PTOA(RCOST,'(P7)',PTOA_FLD);
END

TABLE FILE ibisamp/car
SUM RCOST
BY COUNTRY
BY NEW_FIELD
BY PTOA_FLD
END

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


WebFOCUS 8206, Unix, Windows
July 29, 2016, 11:15 AM
MartinY
DEFINE FILE X
ALPHAFMT /A25 = LJUST(FPRINT(SYVSTAI_CUMULATIVE_GPA,'D20.2','A25'));
END

To decide if it's better in a DEFINE or COMPUTE, it depend on the way you will use it.

Would you like to have all rows converted as alpha (use DEFINE) or just the extracted ones, meaning after Focus has performed the WHERE clause (use COMPUTE) ?
It's a more a question of performance.


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
August 01, 2016, 03:00 PM
Trudy
Thanks for the answers.....

The EDIT solution left zero fill in the output like you said it would
The PTOA solution did not work, it returned a blank field, I believe it did this because the field I was trying to convert was a D20.2
The LJUST(FPRINT()) solution worked but the parameters were different than what was indicated

This is what worked

LJUST(25,(FPRINT( (ACSTHOLD.ACSTHOLD.CUMULATIVE_GPA),'D20.2','A25')),'A6')

Thanks to you both, I learned a lot.


WF8
Windows