Module:Math: Difference between revisions

Adds fraction trapping as an option
en>Dragons flight
m (Protected Module:Math: Going to be used in high profile templates ([Edit=Block all non-admin users] (indefinite) [Move=Block all non-admin users] (indefinite)))
en>Dragons flight
(Adds fraction trapping as an option)
Line 64:
function z.precision( frame )
local input_string = (frame.args[1] or frame.args.x or '0');
local trap_fraction = frame.args.check_fraction or false;
local input_number;
if type( trap_fraction ) == 'string' then
trap_fraction = trap_fraction:lower();
if trap_fraction == 'false' or trap_fraction == '0' or
trap_fraction == 'no' or trap_fraction == '' then
trap_fraction = false;
else
trap_fraction = true;
end
end
if trap_fraction then
local pos = string.find( input_string, '/', 1, true );
if pos ~= nil then
if string.find( input_string, '/', pos + 1, true ) == nil then
local denominator = string.sub( input_string, pos+1, -1 );
local denom_value = tonumber( denominator );
if denom_value ~= nil then
return math.log10(denom_value);
end
end
end
end
input_number, input_string = z._cleanNumber( frame, input_string );
Anonymous user