Data update
This commit is contained in:
parent
07c7092a52
commit
61b93a2cd1
313 changed files with 6160 additions and 346 deletions
59
Task/Number-names/BASIC256/number-names.basic
Normal file
59
Task/Number-names/BASIC256/number-names.basic
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue