Module:Sandbox/Dalba/Num2wordfa Explained

yekan =

dahgan =

sadgan =

exceptions = scale =

function threedigit_words(threedigit) local words = if string.sub(threedigit,1,1) ~= '0' and string.sub(threedigit, 2)~='00' then words = sadgan[tonumber(string.sub(threedigit,1,1))+1] .. ' و ' else words = sadgan[tonumber(string.sub(threedigit,1,1))+1] end if string.sub(threedigit,2,2)

'1' then words = words .. exceptions[tonumber(string.sub(threedigit,3,3))+1] else if string.sub(threedigit,3,3) ~= '0' and string.sub(threedigit,2,2)~='0' then words = words .. dahgan[tonumber(string.sub(threedigit,2,2))+1] .. ' و ' else words = words .. dahgan[tonumber(string.sub(threedigit,2,2))+1] end words = words .. yekan[tonumber(string.sub(threedigit,3,3))+1] end return wordsend

function strnum2words(strnumber) if tonumber(strnumber)

0 then return 'صفر' end if #strnumber > #scale * 3 then print ('Out of range!') end length = #strnumber if length%3 ~=0 then strnumber = string.rep('0', 3-length%3) .. strnumber end groups = (#strnumber) / 3 local words = group = groups while group > 0 do threedigit = string.sub(strnumber, group*3-2, group*3) word3 = threedigit_words(threedigit) if word3 ~= and group ~= groups then if words

then words = word3 .. scale[groups-group+1] else words = word3 .. scale[groups-group+1] .. ' و ' .. words end else words = word3 .. words end group = group - 1 end return sign.. wordsend

function ordinal(nubmer) words = strnum2words(nubmer) if mw.ustring.sub(words,-2)

'سه' then return mw.ustring.sub(words,0,-2) .. 'سوم' else return sign.. words .. 'م' endend

function ordinal2(nubmer) words = strnum2words(nubmer) if mw.ustring.sub(words,-2)

'سه' then return sign .. mw.ustring.sub(words,0,-2) .. 'سومین' else return sign .. words .. 'مین' endend local p = function p.run(frame) number = mw.text.trim(frame.args[1]) if string.sub(number,1,1)

'-' then sign = 'منفی ' number = mw.text.trim(string.sub(number,2)) else sign = end if frame.args[2]

'م' then return ordinal(number) elseif frame.args[2]

'مین' then return ordinal2(number) else return strnum2words(number) endend return p