Module:Simplified fraction: Difference between revisions
Tristanbay (talk | contribs) Maybe I need to initialize ft as empty string? |
Tristanbay (talk | contribs) Undo revision 212838 by Tristanbay (talk) Tag: Undo |
||
| Line 18: | Line 18: | ||
local num, denom = simplify(num, denom) | local num, denom = simplify(num, denom) | ||
local whole = frame.args["mixed"] and math.floor(num / denom) or 0 | local whole = frame.args["mixed"] and math.floor(num / denom) or 0 | ||
local ft | local ft | ||
if d == 1 then | if d == 1 then | ||
ft = | ft = string.format("%d", n) | ||
elseif whole ~= 0 then | elseif whole ~= 0 then | ||
ft = | ft = string.format("{{frac|%d|%d|%d}}", whole, num - whole * denom, denom) | ||
else | else | ||
ft = | ft = string.format("{{frac|%d|%d}}", num, denom) | ||
end | end | ||
return frame:preprocess(ft) | return frame:preprocess(ft) | ||
end | end | ||