Module:Simplified fraction: Difference between revisions

Tristanbay (talk | contribs)
fixed stupid errors I made somehow
Tristanbay (talk | contribs)
Undo revision 214299 by Tristanbay (talk)
Tag: Undo
 
(8 intermediate revisions by the same user not shown)
Line 16: Line 16:
local n = frame.args["n"]
local n = frame.args["n"]
local d = frame.args["d"]
local d = frame.args["d"]
local mixed = frame.args["mixed"] == "true" and true or false
local num, denom = simplify(n, d)
local num, denom = simplify(n, d)
local whole = frame.args["mixed"] and math.floor(num / denom) or 0
local whole = mixed and math.floor(num / denom) or 0
local ft
local ft
if d == 1 then
if denom == 1 then
ft = string.format("%d", n)
ft = string.format("%d", num)
elseif whole ~= 0 then
elseif whole ~= 0 then
ft = string.format("{{frac|%d|%d|%d}}", whole, num - whole * denom, denom)
ft = string.format("%d %d⁄%d", whole, num - whole * denom, denom)
else
else
ft = string.format("{{frac|%d|%d}}", num, denom)
ft = string.format("%d⁄%d", num, denom)
end
end
return frame:preprocess(ft)
return frame:preprocess(ft)
end
end
return p