Cam's Test Wiki
Advertisement

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

--
-- Number manipulation methods
--
-- Many methods are already available in the math library, so this will be fairly small
--

local p = {}

--
-- Rounds a number to a specified number of decimal places
--
-- If dp is not specified, it defaults to zero
-- based on <http://dev.wikia.com/wiki/Module:HF>
--
function p._round( num, dp )
    local mult = 10 ^ ( dp or 0 )
    return math.floor( num * mult + 0.5 ) / mult
end

function p.round( frame )
    -- @todo implement for use as a template or through #invoke
end

--
-- Expands a shorthand number to an actual number
--
-- @example 3.5k -> 3500
-- @example 10m -> 10000000
--
function p._short( str )
    -- get last character from str
    --[[
    local num

    if char == 'k' then
        num = num * 10^3
    elseif char == 'm' then
        num = num * 10^6
    else if char == 'b'
        -- strip trailing letter
        num = num * 10^9
    end

    return num
    ]]
    
end

function p.short( frame )
    -- todo implement for use as a template or through #invoke
end

return p
Advertisement