74 lines
1.7 KiB
Plaintext
74 lines
1.7 KiB
Plaintext
DECLARE FUNCTION int2Text$ (number AS LONG)
|
|
|
|
'small
|
|
DATA "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"
|
|
DATA "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"
|
|
'tens
|
|
DATA "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"
|
|
'big
|
|
DATA "thousand", "million", "billion"
|
|
|
|
DIM SHARED small(1 TO 19) AS STRING, tens(7) AS STRING, big(2) AS STRING
|
|
|
|
DIM tmpInt AS INTEGER
|
|
|
|
FOR tmpInt = 1 TO 19
|
|
READ small(tmpInt)
|
|
NEXT
|
|
FOR tmpInt = 0 TO 7
|
|
READ tens(tmpInt)
|
|
NEXT
|
|
FOR tmpInt = 0 TO 2
|
|
READ big(tmpInt)
|
|
NEXT
|
|
|
|
|
|
DIM n AS LONG
|
|
|
|
INPUT "Gimme a number! ", n
|
|
PRINT int2Text$(n)
|
|
|
|
FUNCTION int2Text$ (number AS LONG)
|
|
DIM num AS LONG, outP AS STRING, unit AS INTEGER
|
|
DIM tmpLng1 AS LONG
|
|
|
|
IF 0 = number THEN
|
|
int2Text$ = "zero"
|
|
EXIT FUNCTION
|
|
END IF
|
|
|
|
num = ABS(number)
|
|
|
|
DO
|
|
tmpLng1 = num MOD 100
|
|
SELECT CASE tmpLng1
|
|
CASE 1 TO 19
|
|
outP = small(tmpLng1) + " " + outP
|
|
CASE 20 TO 99
|
|
SELECT CASE tmpLng1 MOD 10
|
|
CASE 0
|
|
outP = tens((tmpLng1 \ 10) - 2) + " " + outP
|
|
CASE ELSE
|
|
outP = tens((tmpLng1 \ 10) - 2) + "-" + small(tmpLng1 MOD 10) + " " + outP
|
|
END SELECT
|
|
END SELECT
|
|
|
|
tmpLng1 = (num MOD 1000) \ 100
|
|
IF tmpLng1 THEN
|
|
outP = small(tmpLng1) + " hundred " + outP
|
|
END IF
|
|
|
|
num = num \ 1000
|
|
IF num < 1 THEN EXIT DO
|
|
|
|
tmpLng1 = num MOD 1000
|
|
IF tmpLng1 THEN outP = big(unit) + " " + outP
|
|
|
|
unit = unit + 1
|
|
LOOP
|
|
|
|
IF number < 0 THEN outP = "negative " + outP
|
|
|
|
int2Text$ = RTRIM$(outP)
|
|
END FUNCTION
|