60 lines
1.7 KiB
Plaintext
60 lines
1.7 KiB
Plaintext
global lows
|
|
lows = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"}
|
|
global tens
|
|
tens = {"", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"}
|
|
global lev
|
|
lev = {"", "thousand", "million", "billion"}
|
|
|
|
function numname_int(n)
|
|
if n = 0 then return "zero"
|
|
if n < 0 then return "negative " + numname_int(-n)
|
|
t = -1
|
|
redim triples(3) #con < 3 da error ¿¿??
|
|
ret = ""
|
|
|
|
while n > 0
|
|
t += 1
|
|
triples[t] = n mod 1000
|
|
n = int(n / 1000)
|
|
end while
|
|
for i = t to 0 step -1
|
|
tripname = ""
|
|
if triples[i] = 0 then continue for
|
|
lasttwo = triples[i] mod 100
|
|
hundreds = triples[i] \ 100
|
|
if lasttwo < 20 then
|
|
tripname = lows[lasttwo] + tripname + " "
|
|
else
|
|
tripname = tens[lasttwo\10] + "-" + lows[lasttwo mod 10] + " " + tripname
|
|
end if
|
|
if hundreds > 0 then
|
|
if lasttwo > 0 then tripname = " and " + tripname
|
|
tripname = lows[hundreds] + " hundred" + tripname
|
|
end if
|
|
if i = 0 and t > 0 and hundreds = 0 then tripname = " and " + tripname
|
|
tripname += lev[i] + " "
|
|
ret = ltrim(ret) + ltrim(tripname)
|
|
next i
|
|
return trim(ret)
|
|
end function
|
|
|
|
function numname(n)
|
|
ret = ""
|
|
if n = int(n) then return numname_int(int(n))
|
|
prefix = numname_int(int(abs(n))) + " point "
|
|
decdig = string(abs(n)-int(abs(n)))
|
|
if n < 0 then prefix = "negative " + prefix
|
|
ret = prefix
|
|
for i = 3 to length(decdig)
|
|
ret += numname(int(mid(decdig,i,1))) + " "
|
|
next i
|
|
return trim(ret)
|
|
end function
|
|
|
|
print numname(0)
|
|
print numname(1.0)
|
|
print numname(-1.7)
|
|
print numname(910000)
|
|
print numname(987654)
|
|
print numname(100000017)
|