Modulo:Infobox nave: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Moroboshi (discussione | contributi)
fix autoround
arrotondamento eccessivo
 
(11 versioni intermedie di 2 utenti non mostrate)
Riga 27:
 
---============================================================
-- arrotonda in base all'ordine di grandezza: 11111->11110, 1111->1111, 111->111,1
-- Autorounding based on the magnitude of value
---============================================================
local function round_auto(num)
local base = - math.floor(math.log10(math.abs(num))) + 13
if base < -3 then base = -3 end
return round(num, base)
Riga 52:
-- Convert string to number ("," are considered as ".")
---============================================================
local function get_value(stxt)
local s = txt
if s then
s = s:gsub("%.(%d%d%d)", "%1" )
local try_convert = s:gsub(",", ".")
return tonumber(try_convert)
Line 111 ⟶ 113:
function p.speed(frame)
local args = getArgs(frame, {frameOnly = true})
local spd_kn = args[1]
local spd_kmh = args[2]
local spd_type = args[3]
if spd_kmh == nil and spd_kn == nil then return '' end
Line 143 ⟶ 145:
if range_type then dump(out, range_type, ":") end
if nmi_formatted then
dump(out, nmi_formatted, "&nbsp; [[Miglio nautico|miglia]]" )
if kn_formatted then
dump(out, " a ", kn_formatted, "&nbsp;[[nodo (unità di misura)|nodi]]")
Line 166 ⟶ 168:
end
 
---============================================================
-- Format a generic list of measure
---============================================================
function p.measure(frame)
local args = getArgs(frame, {parentOnly = true})
local parameters = getArgs(frame, {frameOnly = true})
local base_arg = parameters[1]
local base_type = parameters[2] or ''
local um = parameters[3]
um = (um and ('&nbsp;' .. um)) or ''
if not base_arg then return end
local elements = {}
local value_txt = args[base_arg]
if not value_txt then return end
local value = get_value(value_txt)
if value then value_txt = format_value(tostring(value)) end
local value_type = args[base_type]
value_type = (value_type and (value_type .. ": ")) or ''
elements[1] = value_type .. value_txt .. um
local n = 2
while true do
local nchar = tostring(n)
value_txt = args[base_arg .. nchar]
if value_txt then
value = get_value(value_txt)
if value then value_txt = format_value(tostring(value)) end
value_type = args[base_type .. nchar]
value_type = (value_type and (value_type .. ": ")) or ''
elements[#elements+1] = value_type .. value_txt .. um
n = n + 1
else
break
end
end
if #elements == 1 then
return elements[1]
else
return '<UL><LI>' .. mw.text.listToText(elements, '</LI>\n<LI>', '</LI>\n<LI>') .. '</LI>\n</UL>'
end
end
return p