Number names: Difference between revisions

Content added Content deleted
Line 3,400: Line 3,400:
if (num == 0) then return "zero" end
if (num == 0) then return "zero" end
local absnum, lion, result = abs(num), 0, ""
local absnum, lion, result = abs(num), 0, ""
local function dashed(n) return n==0 and "" or "-" end
local function dashed(s) return s=="" and s or "-"..s end
local function spaced(s) return s=="" and s or " "..s end
local function spaced(s) return s=="" and s or " "..s end
while (absnum > 0) do
while (absnum > 0) do
Line 3,406: Line 3,406:
if (tens==0) then word = oneslist[ones]
if (tens==0) then word = oneslist[ones]
elseif (tens==1) then word = teenlist[ones]
elseif (tens==1) then word = teenlist[ones]
else word = tenslist[tens] .. dashed(ones) .. oneslist[ones] end
else word = tenslist[tens] .. dashed(oneslist[ones]) end
if (huns > 0) then word = oneslist[huns] .. " hundred" .. spaced(word) end
if (huns > 0) then word = oneslist[huns] .. " hundred" .. spaced(word) end
if (word ~= "") then result = word .. spaced(lionlist[lion]) .. spaced(result) end
if (word ~= "") then result = word .. spaced(lionlist[lion]) .. spaced(result) end