Module:Simplified fraction: Difference between revisions
Tristanbay (talk | contribs) got rid of rational module stuff and replace it with separate function |
Tristanbay (talk | contribs) Undo revision 214299 by Tristanbay (talk) Tag: Undo |
||
| (11 intermediate revisions by the same user not shown) | |||
| Line 10: | Line 10: | ||
b = g | b = g | ||
end | end | ||
return math.floor(n / a), math.floor( | return math.floor(n / a), math.floor(d / a) | ||
end | end | ||
| 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 num, denom = simplify( | local mixed = frame.args["mixed"] == "true" and true or false | ||
local whole = | local num, denom = simplify(n, d) | ||
local whole = mixed and math.floor(num / denom) or 0 | |||
local ft | local ft | ||
if | if denom == 1 then | ||
ft = string.format("%d", | ft = string.format("%d", num) | ||
elseif whole ~= 0 then | elseif whole ~= 0 then | ||
ft = string.format(" | ft = string.format("%d %d⁄%d", whole, num - whole * denom, denom) | ||
else | else | ||
ft = string.format(" | ft = string.format("%d⁄%d", num, denom) | ||
end | end | ||
return frame:preprocess(ft) | return frame:preprocess(ft) | ||
end | end | ||
return p | |||