IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Change number 123 to text as one hundred tweenty three


IBM Mainframe Forums -> IBM Tools
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ghanshyam

New User


Joined: 06 Aug 2006
Posts: 3
Location: delhi

PostPosted: Sun Feb 04, 2007 4:16 pm
Reply with quote

plz tell me


i have enter a number 123 and i want to convert this number to like" one hundred tweenty three"


how can i will do this

thanks
Ghanshyam
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Sun Feb 04, 2007 4:22 pm
Reply with quote

Sounds like one of the first programs I ever wrote, The "check writer" program. COBOL or Assembler?
Back to top
View user's profile Send private message
ofer71

Global Moderator


Joined: 27 Dec 2005
Posts: 2358
Location: Israel

PostPosted: Sun Feb 04, 2007 4:44 pm
Reply with quote

Here is a nice REXX:
Code:
/*------------------------------- REXX ------------------------------- 
 * PROGRAM   : A#31                                                     
 * FUNCTION  : Convert integers (1 - 999999) to words.                 
 * AUTHOR    : ????
 * DATE      : 11/04/05                                                 
 * HOW TO USE:                                                         
 *           :                                                         
 *------------------------------------------------------------------*/ 
                                                                       
"CLEAR"                                                                 
                                                                       
DO K = 100000 TO 110000                                                 
  SAY LEFT(K,6,' ') I2W(K)                                             
END                                                                     
                                                                       
EXIT                                                                   
                                                                       
I2W: PROCEDURE                                                         
                                                                       
I = ARG(1)                                                             
                                                                       
IF I < 1 | I > 999999 THEN                                             
  RETURN 0                                                             
                                                                       
THOUSANDS = I % 1000                                                   
                                                                       
UNITS = I - (THOUSANDS * 1000)                                         
                                                                       
IF THOUSANDS > 0 THEN DO                                               
  RES = I2W(THOUSANDS)||' Thousand'                                     
  IF UNITS > 0 THEN                                                     
    RES = RES||" "||I2W(UNITS)                                         
END                                                                     
ELSE DO                                                                 
  HUNDREDS = UNITS % 100                                               
  UNITS    = UNITS - (HUNDREDS * 100)                                   
  IF HUNDREDS > 0 THEN DO                                               
    RES = I2W(HUNDREDS)||' Hundred'             
  IF UNITS > 0 THEN                             
    RES = RES||" "||I2W(UNITS)                 
  END                                           
  ELSE DO                                       
    SELECT                                     
      WHEN UNITS = 1  THEN RES = "One"         
      WHEN UNITS = 2  THEN RES = "Two"         
      WHEN UNITS = 3  THEN RES = "Three"       
      WHEN UNITS = 4  THEN RES = "Four"         
      WHEN UNITS = 5  THEN RES = "Five"         
      WHEN UNITS = 6  THEN RES = "Six"         
      WHEN UNITS = 7  THEN RES = "Seven"       
      WHEN UNITS = 8  THEN RES = "Eight"       
      WHEN UNITS = 9  THEN RES = "Nine"         
      WHEN UNITS = 10 THEN RES = "Ten"         
      WHEN UNITS = 11 THEN RES = "Eleven"       
      WHEN UNITS = 12 THEN RES = "Twelve"       
      WHEN UNITS = 13 THEN RES = "Thirteen"     
      WHEN UNITS = 14 THEN RES = "Fourteen"     
      WHEN UNITS = 15 THEN RES = "Fifteen"     
      WHEN UNITS = 16 THEN RES = "Sixteen"     
      WHEN UNITS = 17 THEN RES = "Seventeen"   
      WHEN UNITS = 18 THEN RES = "Eighteen"     
      WHEN UNITS = 19 THEN RES = "Nineteen"     
      OTHERWISE DO                             
        TENS = UNITS % 10                       
        UNITS = UNITS - (TENS * 10)             
        SELECT                                 
          WHEN TENS = 2 THEN RES = "Twenty"     
          WHEN TENS = 3 THEN RES = "Thirty"     
          WHEN TENS = 4 THEN RES = "Forty"     
          WHEN TENS = 5 THEN RES = "Fifty"     
          WHEN TENS = 6 THEN RES = "Sixty"     
          WHEN TENS = 7 THEN RES = "Seventy"   
          WHEN TENS = 8 THEN RES = "Eighty"     
          WHEN TENS = 9 THEN RES = "Ninety"     
          OTHERWISE                             
            NOP                           
        END                               
        IF UNITS > 0 THEN                 
          RES = RES||" "||I2W(UNITS)       
      END                                 
    END                                   
  END                                     
END                                       
                                           
RETURN RES                                 
                                           


O.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> IBM Tools

 


Similar Topics
Topic Forum Replies
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Substring number between 2 characters... DFSORT/ICETOOL 2
No new posts Generate random number from range of ... COBOL Programming 3
No new posts Increase the number of columns in the... IBM Tools 3
No new posts 3270 personal communications. Can't c... TSO/ISPF 2
Search our Forums:

Back to Top