Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:NBlocks: Difference between revisions

From Hacks Guide Wiki
No edit summary
No edit summary
Line 25: Line 25:
function p.raw_mib_to_blocks(mib)
function p.raw_mib_to_blocks(mib)
return math.ceil(mib * 8)
return math.ceil(mib * 8)
end
function get_display_unit(size)
if    size >= 1024 * 1024 * 1024 then
return size / 1024 / 1024 / 1024, 'GiB'
elseif size >= 1024 * 1024 then
return size / 1024 / 1024, 'MiB'
elseif size >= 1024 then
return size / 1024, 'KiB'
else
return size, 'bytes'
end
end
end


function p.raw_format_bytes(bytes)
function p.raw_format_bytes(bytes)
-- this needs to do bytes, kib, and gib too
-- this needs to do bytes, kib, and gib too
return string.format("%.2f", bytes / 1024 / 1024) .. ' MiB'
local formatted_size, unit = get_display_unit(bytes)
return string.format("%.2f", formatted_size) .. ' ' .. unit
end
end