Non-decimal radices/Convert: Difference between revisions
Lua: fix case of n = 0
(support 0, fix non-exhaustive matching, use modern API) |
(Lua: fix case of n = 0) |
||
Line 2,252:
Only had to write 'dec2base' as the reverse is provided by the in-built function 'tonumber'
<syntaxhighlight lang="lua">function dec2base (base, n)
local result
local digit = n % base
if digit > 9 then
end▼
result = digit .. result
n = n // base
▲ end
until n == 0
return result
end
|