Jump to content

Module:ConvertMaxWidth

From Shark's Hypothetical Weather
Revision as of 19:17, 3 January 2026 by Sharkius (talk | contribs) (Created page with "local p = {} function p.main(frame) local args = frame.args -- Get input value (yards) local yards = tonumber(args[1]) if not yards then return "Error: Invalid or missing yard value." end -- Decimal precision (default: 1) local precision = tonumber(args['precision']) or 1 -- Abbreviation toggle local abbr = args['abbr'] or 'on' -- Conversions local miles = yards / 1760 local km = yards * 0.0009144 -- Forma...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:ConvertMaxWidth/doc

local p = {}

function p.main(frame)
    local args = frame.args

    -- Get input value (yards)
    local yards = tonumber(args[1])
    if not yards then
        return "Error: Invalid or missing yard value."
    end

    -- Decimal precision (default: 1)
    local precision = tonumber(args['precision']) or 1

    -- Abbreviation toggle
    local abbr = args['abbr'] or 'on'

    -- Conversions
    local miles = yards / 1760
    local km = yards * 0.0009144

    -- Formatting
    local formattedYards = string.format("%,d", yards)
    local formattedMiles = string.format("%." .. precision .. "f", miles)
    local formattedKm = string.format("%." .. precision .. "f", km)

    if abbr == 'on' then
        return formattedYards .. " [[wikipedia:Yard|yards]] (" ..
               formattedMiles .. " [[wikipedia:Mile|mi]]; " ..
               formattedKm .. " [[wikipedia:Kilometre|km]])"
    else
        return formattedYards .. " yards (" ..
               formattedMiles .. " miles; " ..
               formattedKm .. " kilometers)"
    end
end

return p