Module:Simplified fraction: Difference between revisions
Tristanbay (talk | contribs) Created reduced fraction module |
ArrowHead294 (talk | contribs) mNo edit summary |
||
| Line 3: | Line 3: | ||
function p.refrac(frame) | function p.refrac(frame) | ||
local | local n = frame.args["n"] | ||
local d = frame.args["d"] | |||
local num, denom = rat.as_pair(rat.new(n, d)) -- hopefully this reduces the numbers | |||
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 | local ft = (whole ~= 0 and string.format("{{frac|%d|%d|%d}}", whole, num - whole * denom, denom) or string.format("{{frac|%d|%d}}", num, denom)) | ||
return frame:preprocess( | return frame:preprocess(ft) | ||
end | end | ||