Modul:Szám kiírva
Megjelenés
Szám kiírva[mi ez?] • [dokumentáció: mutat, ] • [tesztek: sikeres: 2, sikertelen: 0, kihagyva: 0 (részletek)]
local p = {}
local ones_words = { 'egy', 'két', 'három', 'négy', 'öt', 'hat', 'hét', 'nyolc', 'kilenc' }
local tens_words = { 'tíz', 'húsz', 'harminc', 'negyven', 'ötven', 'hatvan', 'hetven', 'nyolcvan', 'kilencven' }
local function group(number, last)
local ones = number % 10
local tens = (number - ones) % 100
local hundreds = number - (ones + tens)
local text
-- hundreds
if hundreds == 0 then
text = ''
elseif hundreds == 100 then
text = 'száz'
else
text = ones_words[hundreds/100] .. 'száz'
end
-- tens
if tens == 0 then
-- skip
elseif tens == 10 then
if ones == 0 then
text = text .. 'tíz'
else
text = text .. 'tizen'
end
elseif tens == 20 then
if ones == 0 then
text = text .. 'húsz'
else
text = text .. 'huszon'
end
else
text = text .. tens_words[tens/10]
end
-- ones
if ones == 0 then
-- skip
elseif ones == 2 and last then
text = text .. 'kettő'
else
text = text .. ones_words[ones]
end
return text
end
function p._main(number)
number = tonumber(number)
local text = ''
if number and number >= 0 and number < 1E12 and math.abs(number - math.floor(number)) < 1E-12 then
if number == 0 then
text = 'nulla'
elseif number < 1000 then
text = group(number, true)
elseif number < 2000 then
text = 'ezer' .. group(number % 1000, true)
else
local groups = {}
local ones = number % 1000
local thousands = (number - ones) % 1E6
local millions = (number - (ones + thousands)) % 1E9
local billions = number - (ones + thousands + millions)
if billions > 0 then
table.insert(groups, group(billions / 1E9) .. 'milliárd')
end
if millions > 0 then
table.insert(groups, group(millions / 1E6) .. 'millió')
end
if thousands > 0 then
table.insert(groups, group(thousands / 1000) .. 'ezer')
end
if ones > 0 then
table.insert(groups, group(ones, true))
end
text = table.concat(groups, '-')
end
end
return text
end
function p.main(frame)
return p._main(require('Modul:Arguments').getArgs(frame)[1])
end
return p