Nearly 10 years ago, MC-known then as Data Network-published an RPG II program written by Tim Neal. The program converted a numeric value to words, for check-printing purposes. Although a conversion routine like this could be written in many ways, we liked this one for its simplicity.
We often receive calls from AS/400 users requesting an RPG/400 program that will perform the same function. So, we decided it was time to modify the code and republish it. The program (CVT001RG) is shown in 2.
We often receive calls from AS/400 users requesting an RPG/400 program that will perform the same function. So, we decided it was time to modify the code and republish it. The program (CVT001RG) is shown in Figure 2.
It's a separate callable program that requires two parameters: an 8-digit, 2- decimal position, input parameter used to accept the numeric value to be converted; and an 80-character output parameter used to pass back the converted value.
We felt that the maximum value of 999,999.99 would be large enough for most shops. However, modifying it for a larger value should be easy for an RPG programmer since the logic is so simple.
Numbers-to-Words Conversion Program
Figure 2 CVT001RG Program to Convert Numbers to Words
*=============================================================== * To compile: * * CRTRPGPGM PGM(XXX/CVT001RG) SRCFILE(XXX/QRPGSRC) * *=============================================================== *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 E A 6 102 13 IAMT DS I 1 10HTHO I 2 30TTHO I 4 40HUN I 5 60TEN I 1 60DOL I 7 8 CEN C *ENTRY PLIST C PARM AMTIN 82 C PARM WRDS 80 C MOVELAMTIN AMT C HTHO IFGT *ZEROS C CAT A,HTHO:1 WRDSWK 80 C CAT A,100:1 WRDSWK C ENDIF C TTHO IFGT *ZEROS C CAT A,TTHO:1 WRDSWK C CAT A,101:1 WRDSWK C ENDIF C HUN IFGT *ZEROS C CAT A,HUN:1 WRDSWK C CAT A,100:1 WRDSWK C ENDIF C TEN IFGT *ZEROS C CAT A,TEN:1 WRDSWK C ENDIF C DOL IFGT *ZEROS C CAT 'AND':1 WRDSWK C ENDIF C CAT CEN:1 WRDSWK C CAT A,102:0 WRDSWK C 79 SUBSTWRDSWK:2 WRDS 80 P C MOVE *ALL'*' ASTER 80 C CAT ASTER:1 WRDS P C MOVEL*ON *INLR *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ** ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE TEN ELEVEN TWELVE THIRTEEN FOURTEEN FIFTEEN SIXTEEN SEVENTEEN EIGHTEEN NINETEEN TWENTY TWENTY-ON TWENTY-TWO TWENTY-THREE TWENTY-FOUR TWENTY-FIVE TWENTY-SIX TWENTY-SEVEN TWENTY-EIGHT TWENTY-NINE THIRTY THIRTY-ONE THIRTY-TWO THIRTY-THREE THIRTY-FOUR THIRTY-FIVE THIRTY-SIX THIRTY-SEVEN THIRTY-EIGHT THIRTY-NINE FORTY FORTY-ONE FORTY-TWO FORTY-THREE FORTY-FOUR FORTY-FIVE FORTY-SIX FORTY-SEVEN FORTY-EIGHT FORTY-NINE FIFTY FIFTY-ONE FIFTY-TWO FIFTY-THREE FIFTY-FOUR FIFTY-FIVE FIFTY-SIX FIGTY-SEVEN FIGTY-EIGHT FIFTY-NINE SIXTY SIXTY-ONE SIXTY-TWO SIXTY-THREE SIXTY-FOUR SIXTY-FIVE SIXTY-SIX SIXTY-SEVEN SIXTY-EIGHT SIXTY-NINE SEVENTY SEVENTY-ONE SEVENTY-TWO SEVENTY-THREESEVENTY-FOUR SEVENTY-FIVE SEVENTY-SIX SEVENTY-SEVENSEVENTY-EIGHT SEVENTY-NINE EIGHTY EIGHTY-ONE EIGHTY-TWO EIGHTY-THREE EIGHTY-FOUR EIGHTY-FIVE EIGHTY-SIX EIGHTY-SEVEN EIGHTY-EIGHT EIGHTY-NINE NINETY NINETY-ONE NINETY-TWO NINETY-THREE NINETY-FOUR NINETY-FIVE NINETY-SIX NINETY-SEVEN NINETY-EIGHT NINETY-NINE HUNDRED THOUSAND /100
LATEST COMMENTS
MC Press Online