Modul:Lang
Körüniş
Bu modül için bir Modul:Lang/belge belgelendirmesi oluşturabilirsiniz
local p = {};
local MULTIPLIER_WORDS = {
['biñ'] = 1e3,
['mln'] = 1e6,
['mlrd'] = 1e9,
};
function p.formatNum(frame)
local anum = frame.args[1] or '';
local outputType = frame.args[2] or '';
local lang = mw.language.new('ru');
local multiplier = 1
if (outputType == 'R') then
--biñ, mln, mlrd olumaq
for word, value in pairs(MULTIPLIER_WORDS) do
number, realWord = anum:match("(.*)%s*(" .. word .. ")%.?")
if realWord == word then
multiplier = multiplier * value
anum = number
end
end
end
-- boşluqlar yoq etmek:
local preprocessedNumber = anum:gsub("%s", "")
local preprocessedNumber = preprocessedNumber:gsub(" ", "")
local preprocessedNumber = preprocessedNumber:gsub(" ", "")
local num = lang:parseFormattedNumber(preprocessedNumber);
if num ~= nil then
if outputType == 'R' then
return num * multiplier
else
return lang:formatNum(num);
end
else
return anum;
end
end
function p._extractNum(s)
local num = s:match("(%d+([,.]%d+))")
if num == nil then
num = s:match("%d+")
end
return num
end
function p.extractNum(frame)
local anum = frame.args[1] or '';
local num = p._extractNum(anum)
return num
end
return p