at lunch (pizza with gorgonzola & plenty of wine) i thought to myself; the change to any long number should not be very complicated... it really was not...
hier ist die aenderung:
// n2w-fal-01b words01 (ori. base: falcon)
// input as string: Any length
// 2021/05/08 - nestor kuka
// -----------------------------------------------------------------------
w = " " // str. container f. woerter
ww = " " // str. container f. display result
// global - units: 1-19
u = ["","One","Two","Three","Four","Five","Six","Seven","Eight","Nine",
"Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen",
"Seventeen","Eighteen","Nineteen"]
words = function( i ) // ------------------------------ group conversion
// tens: 20-90
t = ["","","Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"]
if i > 99 then // 100 - 999
w = u[(i-(i%100))/100] ; w = w + " hundred " ; w = w + words( i % 100)
end if
if i < 20 then // 1 - 19
w = u[i]
end if
if i > 20 and i < 100 then // 21 - 99
w = t[(i-(i % 10)) /10] ; w = w + " " ; w = w + words(i % 10)
end if
return w
end function
//i = 101 // *** test: words ***
//print words( i ) // show test
mils = function( n ) // ------------------------------------- main loop
// mills group names:
m = ["","thousand ", "million ", "billion ", "trillion ", "quadrillion ", "quintillion ", "sextillion", "septillion", "octillion", "nonillion", "decillion", "undecillion", "duodecillion", "tredecillion", "quattuordecillion", "sexdecillion", "septendecillion", "octodecillion", "novemdecillion", "vigintillion ","..."]
anz_gr = floor((n.len+2)/3) // anzahl gruppen
print "anz_gr: "+ anz_gr
milcount = 0
for i in range(1, anz_gr)
gr = n[-3:]
print " ----> three aktuell: " + gr
// ************************************************
i = val(gr) // conv three to num
// ************************************************
// issue test:
print "words: "+ words(i) +" "+ m[milcount] // 3er-gruppen
// make number to word:
ww = words(i) +" "+ m[milcount] + ww // concat. w
print("------------------------------------------ ")
// *** v01b - string auswertung & neu bestimmung:
sl = n.len - 3
print "neue n.len: " + sl // neue str len
ns = slice(n, 0, -3) //neuer string
print "ns neuer string: " + ns
print "--------"
n = ns
// neue str wird alter str
milcount = milcount + 1
// *** end v01b ----------------------------------
end for
print "ww: "+ww // *** display result ***
end function
// ------------------------------------------------------------ input-info
n = "12345678909876543210123456789098765432100987654321" // Any length
print "Input: " + n + " (No. of digits: "+ n.len + ")"
print("-------------------------------------------- ")
print mils( n ) // main func. param: string
// ------------------------------------------------------------ end of pgm