Module:number base: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 6: | Line 6: | ||
function export.base12(n) | function export.base12(n) | ||
n = floor(tonumber(n)) | n = floor(tonumber(n)) | ||
local digits = " | local digits = "0123456789SR" | ||
local t = {} | local t = {} | ||
repeat | repeat |
Revision as of 22:57, 30 June 2023
Documentation for this module may be created at Module:number base/doc
local export = {}
local floor, insert = math.floor, table.insert
-- Ross Berteig on SO: https://stackoverflow.com/a/3554821
function export.base12(n)
n = floor(tonumber(n))
local digits = "0123456789SR"
local t = {}
repeat
local d = (n % 12) + 1
n = floor(n / 12)
insert(t, 1, digits:sub(d,d))
until n == 0
return table.concat(t)
end
return export