Mòdul:Proves/Vriullop
Aparença
Documentació del mòdul [ mostra ] [ modifica el codi ] [ mostra l'historial ] [ refresca ]
A continuació es mostra la documentació transclosa de la subpàgina /ús. [salta a la caixa de codi]
local p = {}
function p.bytes(frame)
local title = frame.args[1]
return mw.language.getContentLanguage():formatNum(string.len(mw.title.new(title):getContent() or ''))
end
-- Engineering notation
-- Credit to https://stackoverflow.com/questions/17973278 cc-by-sa-4.0
function p.engNotation(frame)
local x = tonumber(frame.args[1])
local sign = ''
if x < 0 then
x = math.abs(x)
sign = '-'
end
local exp = math.floor(math.log10(x))
local exp3 = exp - (exp % 3)
local x3 = x / (10 ^ exp3)
local exp3_text
if exp3 == 0 then
exp3_text = ''
elseif exp3 >= -24 and exp3 <= 24 then
local index = (exp3 - (-24)) / 3 + 1
exp3_text = ' ' .. mw.ustring.sub('yzafpnµm kMGTPEZY', index, index)
else
exp3_text = ' e' .. tostring(exp3)
end
return sign .. tostring(x3) .. exp3_text
end
return p