Module:Test: Difference between revisions

From Roat Pkz
Jump to navigation Jump to search
No edit summary
No edit summary
Line 12: Line 12:
     -- Original number
     -- Original number
     table.insert(percentages, number)
     table.insert(percentages, number)
     -- 10% increase
     -- 10% decrease
     table.insert(percentages, number * 1.10)
     table.insert(percentages, number - (number * 0.10))
     -- 20% increase
     -- 20% decrease
     table.insert(percentages, number * 1.20)
     table.insert(percentages, number - (number * 0.20))
     -- 30% increase
     -- 30% decrease
     table.insert(percentages, number * 1.30)
     table.insert(percentages, number - (number * 0.30))
      
      
     -- Format the result as a table
     -- Format the result as a table
     local resultTable = "{| class=\"wikitable\"\n"
     local resultTable = "{| class=\"wikitable\"\n"
     resultTable = resultTable .. "! Original !! +10% !! +20% !! +30%\n|-\n"
     resultTable = resultTable .. "! Original !! -10% !! -20% !! -30%\n|-\n"
     resultTable = resultTable .. "| " .. number .. " || " .. percentages[2] .. " || " .. percentages[3] .. " || " .. percentages[4] .. "\n|}"
     resultTable = resultTable .. "| " .. number .. " || " .. percentages[2] .. " || " .. percentages[3] .. " || " .. percentages[4] .. "\n|}"
      
      

Revision as of 22:47, 3 April 2024

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

-- This is a Lua module for MediaWiki
-- It provides functionality to calculate percentages of a number

-- Create a table to hold the functions
local Test = {}

-- Function to calculate percentages
function Test.calculatePercentages(frame)
    local args = frame.args
    local number = tonumber(args[1]) or 0 -- Extract the number from the args
    local percentages = {}
    -- Original number
    table.insert(percentages, number)
    -- 10% decrease
    table.insert(percentages, number - (number * 0.10))
    -- 20% decrease
    table.insert(percentages, number - (number * 0.20))
    -- 30% decrease
    table.insert(percentages, number - (number * 0.30))
    
    -- Format the result as a table
    local resultTable = "{| class=\"wikitable\"\n"
    resultTable = resultTable .. "! Original !! -10% !! -20% !! -30%\n|-\n"
    resultTable = resultTable .. "| " .. number .. " || " .. percentages[2] .. " || " .. percentages[3] .. " || " .. percentages[4] .. "\n|}"
    
    return resultTable
end

-- Export the module
return Test