« Module:WeightToPercent » : différence entre les versions

De eMushpedia
Aller à la navigation Aller à la recherche
Création du script pour convertir les poids en pourcentages facilement
 
Evian (discussion | contributions)
Annulation des modifications 5363 de Evian (discussion)
 
(9 versions intermédiaires par 2 utilisateurs non affichées)
Ligne 1 : Ligne 1 :
local p = {} --p stands for package
local p = {}
 
function convert(weight, totalweight)
function p.convert(frame)
if weight == 0 then return 0
local weight = frame.args['weight']
     else return 100 * totalweight / weight end
local totalweight = frame.args['total']
if weight == nil then return "ERROR: weight input (1rst arg) is nil"
elseif totalweight == nil then return "ERROR: totalweight (2nd arg) input is nil"
elseif weight == 0 then return 0
     end
    return tonumber(string.format("%.1f", weight * 100 / totalweight))
end
end
   
   
return p
return p

Dernière version du 2 mars 2026 à 18:06

La documentation pour ce module peut être créée à Module:WeightToPercent/doc

local p = {}

function p.convert(frame)
	local weight = frame.args['weight']
	local totalweight = frame.args['total']
	
	if weight == nil then return "ERROR: weight input (1rst arg) is nil"
	elseif totalweight == nil then return "ERROR: totalweight (2nd arg) input is nil"
	elseif weight == 0 then return 0
    end
    return tonumber(string.format("%.1f", weight * 100 / totalweight))
end
 
return p