Number names: Difference between revisions
Content added Content deleted
(Added BASIC256) |
|||
Line 862: | Line 862: | ||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
{{works with|QBasic}} |
{{works with|QBasic}} |
||
<syntaxhighlight lang="qbasic">DECLARE FUNCTION int2Text$ (number AS LONG) |
<syntaxhighlight lang="qbasic">DECLARE FUNCTION int2Text$ (number AS LONG) |
||
Line 936: | Line 935: | ||
int2Text$ = RTRIM$(outP) |
int2Text$ = RTRIM$(outP) |
||
END FUNCTION</syntaxhighlight> |
END FUNCTION</syntaxhighlight> |
||
{{out|Sample outputs}} (including the answer to the ultimate question of life, the universe, and everything): |
{{out|Sample outputs}} (including the answer to the ultimate question of life, the universe, and everything): |
||
<pre> |
<pre> Gimme a number! 1 |
||
Gimme a number! 1 |
|||
one |
one |
||
Gimme a number! 0 |
Gimme a number! 0 |
||
Line 952: | Line 949: | ||
one billion one |
one billion one |
||
Gimme a number! &h7fffffff |
Gimme a number! &h7fffffff |
||
two billion one hundred forty-seven million four hundred eighty-three thousand six hundred forty-seven |
two billion one hundred forty-seven million four hundred eighty-three thousand six hundred forty-seven</pre> |
||
</pre> |
|||
=={{header|BASIC256}}== |
|||
{{trans|FreeBASIC}} |
|||
<syntaxhighlight lang="vb">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)</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Same as FreeBASIC entry.</pre> |
|||
=={{header|Batch File}}== |
=={{header|Batch File}}== |