Jump to content

Module:Convert to eastern arabic numerals and Module:Convert to eastern arabic numerals/sandbox: Difference between pages

(Difference between pages)
Content deleted Content added
m Comma "," (U+002C) → Arabic Decimal Separator "٫" (U+066B)
 
Try slight refactor
 
Line 1: Line 1:
local p = {}
local p = {}


local conversion_table = {
local = {
['0'] = '٠',
[0] = ٠,
['1'] = '١',
[1] = ١,
['2'] = '٢',
[2] = ٢,
['3'] = '٣',
[3] = ٣,
['4'] = '٤',
[4] = ٤,
['5'] = '٥',
[5] = ٥,
['6'] = '٦',
[6] = ٦,
['7'] = '٧',
[7] = ٧,
['8'] = '٨',
[8] = ٨,
['9'] = '٩',
[9] = ٩,
['.'] = '٫'
[.] =
}
}


function p._convert(args)
function p._convert(args)
if args == nil then
if args then
return 'Error! Arguments provided are null'
return Error! Arguments provided are null
end
end
local num_str = tostring(args[1])
if args[1] == nil then
local new_str = string.gsub(num_str, [0-9.], )
return ''
return
end
local num_str = tostring(args[1])
local new_str, _ = string.gsub(num_str, '[0-9.]', conversion_table)
return new_str
end
end


function p.convert(frame)
function p.convert(frame)
return p._convert(frame.args)
return p._convert(frame.args)
end
end