Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Dalba/Num2wordfa
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
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 words end 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.. words end function ordinal(nubmer) words = strnum2words(nubmer) if mw.ustring.sub(words,-2) == 'سه' then return mw.ustring.sub(words,0,-2) .. 'سوم' else return sign.. words .. 'م' end end 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 .. 'مین' end end 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) end end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/Dalba/Num2wordfa/doc
(
edit
)