Module:Math: Difference between revisions

no edit summary
en>Dragons flight
(can't work due to prehandling by #expr, simplify)
en>Dragons flight
No edit summary
Line 101:
return min_value
end
 
-- Rounds a number to specified precision
function z.round(frame)
local value = tonumber(frame.args[1] or frame.args.value or 0);
local precision = tonumber(frame.args[2] or frame.args.precision or 0);
return z._round( value, precision );
end
function z._round( value, precision )
local rescale = math.pow( 10, precision );
value =return math.floor( value * rescale + 0.5 ) / rescale;
end
 
-- Rounds a number to the specified precision and formats according to rules
-- originally used for {{template:Rnd}}. Output is a string.
function z.roundprecision_format( frame )
-- For access to Mediawiki built-in formatter.
local lang = mw.getContentLanguage();
Line 123 ⟶ 134:
-- If rounding off, truncate extra digits
if precision < current_precision then
local rescalevalue = mathz.pow_round( 10value, precision );
value = math.floor( value * rescale + 0.5 ) / rescale;
current_precision = z._precision( value );
end
Anonymous user