Number names: Difference between revisions

Updated to compile with Nim 1.4. Other minor changes.
m (Regularize non-standard header markup)
(Updated to compile with Nim 1.4. Other minor changes.)
Line 3,727:
"decillion"]
 
# Forward reference.
proc spellInteger(n: int64): string
 
proc nonzero(c: string,; n: int,int64; connect = ""): string =
if n == 0: "" else: connect & c & spellInteger(n)
 
proc lastAnd(num: string): string =
varif num',' =in num:
if "," inlet pos = num:.rfind(',')
letvar (pre, last) = if pos >= 0: (num[0 .rfind(".< pos]," num[pos+1 .. num.high])
var else: (pre"", lastnum) =
if " ifand pos" >=notin 0last: (num[0last ..= pos-1]," num[pos+1and" ..& num.high])last
result = else:[pre, (",", numlast].join()
else:
if " and " notin last:
lastresult = " and" & lastnum
num = [pre, ",", last].join()
return num
 
proc big(e, n: int64): string =
if e == 0:
spellInteger(n)
Line 3,752 ⟶ 3,751:
spellInteger(n) & " " & huge[e]
 
iterator base1000Rev(n: int64): intint64 =
var n = n
while n != 0:
Line 3,776 ⟶ 3,775:
var e = 0
for x in base1000Rev(n):
if x > 0: sq.add big(e, x)
sq.add big(e, x)
inc e
reverse sq
Line 3,789 ⟶ 3,787:
echo align($n, 14)," -> ",spellInteger(n)
n = n div -10</lang>
 
Output:
{{out}}
<pre> 0 -> zero
-3 -> minus three
Anonymous user