Number names: Difference between revisions
Added Easylang
(Added Easylang) |
|||
(5 intermediate revisions by 5 users not shown) | |||
Line 862:
=={{header|BASIC}}==
{{works with|QBasic}}
<syntaxhighlight lang="qbasic">DECLARE FUNCTION int2Text$ (number AS LONG)
Line 936 ⟶ 935:
int2Text$ = RTRIM$(outP)
END FUNCTION</syntaxhighlight>
{{out|Sample outputs}} (including the answer to the ultimate question of life, the universe, and everything):
<pre> Gimme a number! 1
one
Gimme a number! 0
Line 952 ⟶ 949:
one billion one
Gimme a number! &h7fffffff
two billion one hundred forty-seven million four hundred eighty-three thousand six hundred forty-seven</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}}==
Line 2,022 ⟶ 2,082:
Readln;
end.</syntaxhighlight>
=={{header|EasyLang}}==
{{trans|Go}}
<syntaxhighlight>
small$[] = [ "zero" "one" "two" "three" "four" "five" "six" "seven" "eight" "nine" "ten" "eleven" "twelve" "thirteen" "fourteen" "fifteen" "sixteen" "seventeen" "eighteen" "nineteen" ]
tens$[] = [ "" "" "twenty" "thirty" "forty" "fifty" "sixty" "seventy" "eighty" "ninety" ]
illions$[] = [ "" " thousand" " million" " billion" " trillion" " quadrillion" " quintillion" ]
func$ say n .
if n < 0
t$ = "negative "
n = -n
.
if n < 20
t$ &= small$[n + 1]
elif n < 100
t$ &= tens$[n div 10 + 1]
s = n mod 10
if s > 0
t$ &= "-" & small$[s + 1]
.
elif n < 1000
t$ &= small$[n div 100 + 1] & " hundred"
s = n mod 100
if s > 0
t$ &= " " & say s
.
else
i = 1
while n > 0
p = n mod 1000
n = n div 1000
if p > 0
ix$ = say p & illions$[i]
if sx$ <> ""
ix$ &= " " & sx$
.
sx$ = ix$
.
i += 1
.
t$ &= sx$
.
return t$
.
for n in [ 12 1048576 9e18 -2 0 ]
print say n
.
</syntaxhighlight>
{{out}}
<pre>
twelve
one million forty-eight thousand five hundred seventy-six
nine quintillion
negative two
zero
</pre>
=={{header|Ecstasy}}==
Line 2,636 ⟶ 2,752:
=={{header|Go}}==
Line 5,531 ⟶ 5,638:
{{trans|C#}}
<syntaxhighlight lang="quackery">[ [ table
$ "zero" $ "one" $ "two"
$ "three" $ "four" $ "five"
Line 5,540 ⟶ 5,646:
$ "fourteen" $ "fifteen"
$ "sixteen" $ "seventeen"
$ "eighteen" $ "nineteen" ] do ] is units ( n --> $ )
[ [ table
Line 5,546 ⟶ 5,652:
$ "thirty" $ "fourty" $ "fifty"
$ "sixty" $ "seventy" $ "eighty"
$ "ninety" ] do ] is tens ( n --> $ )
[ $ "" swap
Line 5,563 ⟶ 5,669:
[ over -1 peek space != if
[ dip [ space join ] ] ]
units join ] is triplet ( n --> $ )
[ $ "" swap
dup 999999999999999 > if
[ 1000000000000000 /mod swap triplet
$ " quadrillion" join
swap dip join
dup 0 = iff drop ]done[ ]
dup 999999999999 > if
[ over size 0 > if
[ dip [ $ ", " join ] ]
1000000000000 /mod swap triplet
$ " trillion" join
swap dip join
dup 0 = iff drop ]done[ ]
dup 999999999 > if
[ over size 0 > if
[ dip [ $ ", " join ] ]
1000000000 /mod swap triplet
$ " billion" join
swap dip join
dup 0 = iff drop ]done[ ]
dup 999999 > if
[
[ dip [ $ ", " join ] ]
1000000 /mod swap triplet
$ " million" join
swap dip join
Line 5,580 ⟶ 5,707:
over size 0 > if
[ dip [ $ ", " join ] ]
triplet join
dup reverse witheach
[ char , = if
[ i split
behead drop
$ " and" swap
join join
conclude ] ] ] is name$ ( n --> $ )
10 times
[ 10
1+ ** random
dup echo
say " is:"
name$ nest$
60 wrap$ cr cr ]</syntaxhighlight>
{{out}}
<pre>
hundred and ninety one
four
seven hundred, seventy seven billion, one hundred million,
eight hundred, fifty one thousand, two hundred and thirty
six
three
hundred, ninety nine thousand, five hundred and thirteen
million, three hundred, eighty six thousand, three hundred
and seventy
eight
four
47022976290599343 is:
fourty seven quadrillion, twenty two trillion, nine hundred,
seventy six billion, two hundred, ninety million, five
hundred, ninety nine thousand, three hundred and fourty
three</pre>
=={{header|R}}==
Line 6,463 ⟶ 6,598:
var integer: number is 0;
begin
for number range 1 to
writeln(str(ENGLISH, number));
end for;
Line 7,310 ⟶ 7,445:
{{trans|Go}}
Although the third example here works correctly, it is not safe to use this script for numbers with an absolute magnitude >= 2^53 as integers cannot be expressed exactly by Wren's Num type beyond that limit.
<syntaxhighlight lang="
"twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"]
|