Currency to Words

 

This program is part of a collection of input/output field editing routines I have written over the years, but most of the other routines implemented functions that are just as easily coded directly in GnuCOBOL or are provided by intrinsic functions.  But this program still has utility.

The first version of this code was written in 1976 in Burroughs COBOL as the result of a co-worker telling me it couldn't be done.  Specifically he said it couldn't be coded in COBOL to execute efficiently enough to be able to use in a production environment ("Hi Robert, if you read this!"); I stayed late that night and left a 2 inch stack of print-out on his desk with the test results and execution time.  My code found its way into our payroll system shortly thereafter.  It was next translated into RM COBOL and MVS COBOL.  Another co-worker needed this functionality at another job, and since I had just converted it to RM COBOL for my own use on my first PC (a Texas Instruments Professional, which was mostly IBM PC compatible), I didn't see any need for him to waste time recoding it.  

This current version was coded from scratch following the logic of the 370ALC version I wrote in the early 1990s, since I seem to have misplaced every copy of the earlier COBOL versions.

I also modified the installation verification program for the field editing routines to pare it down to exercise only this program.  That testing program is also included.

To install the source for the subroutine and the test program, and compile them, execute the bash script:  MONY.setup [md5: 2426435c3b162f3a3d30147a1539f2b4].  Right click and save the script in the location where you want the source programs to reside, then execute it.  It will create two files containing the source programs, then execute the GnuCOBOL compiler to compile them, and finally will execute a test program to produce sample output in the file TESTMONY.rpt.  The GnuCOBOL compiler must be installed prior to executing the bash script.  

In order to dynamically call the subroutine from other programs, you must copy the object module (OFMTMONY.so) to a location available through the COB_LIBRARY_PATH.

If you execute the test program it will create a report (TESTMONY.rpt):

DATE: 05/16/2016                              TESTING CURRENCY-TO-WORDS SUBROUTINE                                 PROGRAM: TESTMONY
TIME: 10:22                                    INSTALLATION VERIFICATION PROGRAM                                      PAGE:      1

 TEST DATA INPUT VALUE                                                 R/C
 00,000,000,000.01                                                      0   ONLY 1 CENT *******************************************
                                                                            *******************************************************
                                                                            **************************************************
------------------------------------------------------------------------------------------------------------------------------------
 99,999,999,999.99           maximum input value                        0   NINETY-NINE BILLION, NINE HUNDRED NINETY-NINE MILLION,
                                                                            NINE HUNDRED NINETY-NINE THOUSAND, NINE HUNDRED NINETY-
                                                                            NINE DOLLARS AND 99 CENTS ************************
------------------------------------------------------------------------------------------------------------------------------------
 77,777,777,777.77           longest output, 146 characters             0   SEVENTY-SEVEN BILLION, SEVEN HUNDRED SEVENTY-SEVEN MILL
                                                                            ION, SEVEN HUNDRED SEVENTY-SEVEN THOUSAND, SEVEN HUNDRE
                                                                            D SEVENTY-SEVEN DOLLARS AND 77 CENTS *************
------------------------------------------------------------------------------------------------------------------------------------
 00,000,000,138.59                                                      0   ONE HUNDRED THIRTY-EIGHT DOLLARS AND 59 CENTS *********
                                                                            *******************************************************
                                                                            **************************************************
------------------------------------------------------------------------------------------------------------------------------------
 04,000,707,000.85                                                      0   FOUR BILLION, SEVEN HUNDRED AND SEVEN THOUSAND DOLLARS
                                                                            AND 85 CENTS ******************************************
                                                                            **************************************************
------------------------------------------------------------------------------------------------------------------------------------
 00,691,000,578.51                                                      0   SIX HUNDRED NINETY-ONE MILLION, FIVE HUNDRED SEVENTY-EI
                                                                            GHT DOLLARS AND 51 CENTS ******************************
                                                                            **************************************************
------------------------------------------------------------------------------------------------------------------------------------
 59,903,000,000.79                                                      0   FIFTY-NINE BILLION, NINE HUNDRED AND THREE MILLION DOLL
                                                                            ARS AND 79 CENTS **************************************
                                                                            **************************************************
------------------------------------------------------------------------------------------------------------------------------------
 05,000,000,000.57                                                      0   FIVE BILLION DOLLARS AND 57 CENTS *********************
                                                                            *******************************************************
                                                                            **************************************************
------------------------------------------------------------------------------------------------------------------------------------
 00,000,102,000.18                                                      0   ONE HUNDRED AND TWO THOUSAND DOLLARS AND 18 CENTS *****
                                                                            *******************************************************
                                                                            **************************************************
------------------------------------------------------------------------------------------------------------------------------------
 86,000,628,772.00                                                      0   EIGHTY-SIX BILLION, SIX HUNDRED TWENTY-EIGHT THOUSAND,
                                                                            SEVEN HUNDRED SEVENTY-TWO DOLLARS AND NO CENTS ********
DATE: 05/16/2016                              TESTING CURRENCY-TO-WORDS SUBROUTINE                                 PROGRAM: TESTMONY
TIME: 10:22                                    INSTALLATION VERIFICATION PROGRAM                                      PAGE:      2

 TEST DATA INPUT VALUE                                                 R/C
                                                                            **************************************************
------------------------------------------------------------------------------------------------------------------------------------
 39,000,000,068.89                                                      0   THIRTY-NINE BILLION, SIXTY-EIGHT DOLLARS AND 89 CENTS *
                                                                            *******************************************************
                                                                            **************************************************
------------------------------------------------------------------------------------------------------------------------------------
 17,000,774,207.98                                                      0   SEVENTEEN BILLION, SEVEN HUNDRED SEVENTY-FOUR THOUSAND,
                                                                             TWO HUNDRED AND SEVEN DOLLARS AND 98 CENTS ***********
                                                                            **************************************************
------------------------------------------------------------------------------------------------------------------------------------
 00,878,520,000.34                                                      0   EIGHT HUNDRED SEVENTY-EIGHT MILLION, FIVE HUNDRED TWENT
                                                                            Y THOUSAND DOLLARS AND 34 CENTS ***********************
                                                                            **************************************************
------------------------------------------------------------------------------------------------------------------------------------
 00,000,000,219.01                                                      0   TWO HUNDRED NINETEEN DOLLARS AND 1 CENT ***************
                                                                            *******************************************************
                                                                            **************************************************
------------------------------------------------------------------------------------------------------------------------------------
 A ,CDE,F12,345.67           non-numeric characters input              *8*  *******************************************************
                                                                            *******************************************************
                                                                            **************************************************
------------------------------------------------------------------------------------------------------------------------------------
 01,000,000,156.39                                                      0   ONE BILLION, ONE HUNDRED FIFTY-SIX DOLLARS AND 39 CENTS
                                                                             ******************************************************
                                                                            **************************************************
------------------------------------------------------------------------------------------------------------------------------------
 86,978,902,496.15-          negative input                            *4*  V O I D ***********************************************
                                                                            *******************************************************
                                                                            **************************************************
------------------------------------------------------------------------------------------------------------------------------------
 00,576,747,000.73                                                      0   FIVE HUNDRED SEVENTY-SIX MILLION, SEVEN HUNDRED FORTY-S
                                                                            EVEN THOUSAND DOLLARS AND 73 CENTS ********************
                                                                            **************************************************
------------------------------------------------------------------------------------------------------------------------------------
 00,000,000,000.00           zero value input                           0   V O I D ***********************************************
                                                                            *******************************************************
                                                                            **************************************************
------------------------------------------------------------------------------------------------------------------------------------
DATE: 05/16/2016                              TESTING CURRENCY-TO-WORDS SUBROUTINE                                 PROGRAM: TESTMONY
TIME: 10:22                                    INSTALLATION VERIFICATION PROGRAM                                      PAGE:      3

 TEST DATA INPUT VALUE                                                 R/C
 52,328,202,652.24                                                      0   FIFTY-TWO BILLION, THREE HUNDRED TWENTY-EIGHT MILLION,
                                                                            TWO HUNDRED AND TWO THOUSAND, SIX HUNDRED FIFTY-TWO DOL
                                                                            LARS AND 24 CENTS ********************************
------------------------------------------------------------------------------------------------------------------------------------
 00,105,609,201.00                                                      0   ONE HUNDRED AND FIVE MILLION, SIX HUNDRED AND NINE THOU
                                                                            SAND, TWO HUNDRED AND ONE DOLLARS AND NO CENTS ********
                                                                            **************************************************
------------------------------------------------------------------------------------------------------------------------------------
 10,203,040,506.07                                                      0   TEN BILLION, TWO HUNDRED AND THREE MILLION, FORTY THOUS
                                                                            AND, FIVE HUNDRED AND SIX DOLLARS AND 7 CENTS *********
                                                                            **************************************************
------------------------------------------------------------------------------------------------------------------------------------
 55,000,288,000.97                                                      0   FIFTY-FIVE BILLION, TWO HUNDRED EIGHTY-EIGHT THOUSAND D
                                                                            OLLARS AND 97 CENTS ***********************************
                                                                            **************************************************
------------------------------------------------------------------------------------------------------------------------------------
 86,000,162,491.45                                                      0   EIGHTY-SIX BILLION, ONE HUNDRED SIXTY-TWO THOUSAND, FOU
                                                                            R HUNDRED NINETY-ONE DOLLARS AND 45 CENTS *************
                                                                            **************************************************
------------------------------------------------------------------------------------------------------------------------------------
 00,000,002,138.25                                                      0   TWO THOUSAND, ONE HUNDRED THIRTY-EIGHT DOLLARS AND 25 C
                                                                            ENTS **************************************************
                                                                            **************************************************
------------------------------------------------------------------------------------------------------------------------------------
comments in blue added by me will not appear on test program output

This page was last updated on April 06, 2021.