View previous topic :: View next topic
|
Author |
Message |
ghanshyam
New User
Joined: 06 Aug 2006 Posts: 3 Location: delhi
|
|
|
|
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 |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Sounds like one of the first programs I ever wrote, The "check writer" program. COBOL or Assembler? |
|
Back to top |
|
|
ofer71
Global Moderator
Joined: 27 Dec 2005 Posts: 2358 Location: Israel
|
|
|
|
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 |
|
|
|