Module:Simplified fraction: Difference between revisions
Jump to navigation
Jump to search
Tristanbay (talk | contribs) seeing if this fixes the nil value returned |
Tristanbay (talk | contribs) seeing if this fixes the nil value now |
||
| Line 7: | Line 7: | ||
local num, denom = rat.as_pair(rat.new(n, d)) -- hopefully this reduces the numbers | local num, denom = rat.as_pair(rat.new(n, d)) -- hopefully this reduces the numbers | ||
local whole = frame.args["mixed"] ~= 0 and math.floor(num / denom) or 0 | local whole = frame.args["mixed"] ~= 0 and math.floor(num / denom) or 0 | ||
local ft | local ft | ||
if whole ~= 0 then | |||
ft = string.format("{{frac|%d|%d|%d}}", whole, num - whole * denom, denom) | |||
else | |||
ft = string.format("{{frac|%d|%d}}", num, denom) | |||
end | |||
return frame:preprocess(ft) | return frame:preprocess(ft) | ||
end | end | ||
Revision as of 05:24, 12 October 2025
- This module implements a template that is currently missing or does not use this module. (edit template)
This module automatically creates a fraction in simplest form from a numerator and denominator. Whether the fraction is in a mixed form or not when greater than 1 can be controlled using the mixed parameter.
| Introspection summary for Module:Simplified fraction | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
| ||||||||||||
No function descriptions were provided. The Lua code may have further information.
local p = {}
local rat = require("Module:Rational")
function p.refrac(frame)
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"] ~= 0 and math.floor(num / denom) or 0
local ft
if whole ~= 0 then
ft = string.format("{{frac|%d|%d|%d}}", whole, num - whole * denom, denom)
else
ft = string.format("{{frac|%d|%d}}", num, denom)
end
return frame:preprocess(ft)
end