1 Reply Latest reply on Aug 28, 2017 1:48 AM by try67

    How to convert a decimal number to arabic word

    Alex Doubts Level 1

      Hai i have been converting a decimal number to english word using below script. Is anybody help me to convert the same to arabic word ?

       

       

      var th = ['', 'thousand', 'million', 'billion', 'trillion'];

      var dg = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];

      var tn = ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'];

      var tw = ['twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'];

       

       

      //-------------------------------------------------------

      function num2String(s1) {

          var num = s1.toString();

          var s2 = num.split('.');

          var decPoint = '';

          var lang = '';

       

       

          if (s2.length > 1) {

              if (s2[1].length == 1)

                  s2[1] = s2[1] * 10;

              if (getField("ddlDebitCurrency").value == "0" || getField("ddlDebitCurrency").value == "Others")

                  decPoint = ' and ' + toWords(s2[1]) + ' ';

              else

                  decPoint = ' and ' + toWords(s2[1]) + GetCurrencyDetails(getField("ddlDebitCurrency").value, 1);

          }

          if (getField("ddlDebitCurrency").value == "0" || getField("ddlDebitCurrency").value == "Others")

              lang = '' + toWords(s2[0]) + decPoint + ' only';

          else

              lang = getField("ddlDebitCurrency").value + ' ' + toWords(s2[0]) + decPoint + ' only';

       

       

          lang = lang.replace('   ', ' ');

          return lang.replace('  ', ' ');

      }

      //------------------------------------------------------------

       

       

       

       

      //-----------------------------------------

       

       

      function GetCurrencyDetails(strCurrencyCode, flgCurType) {

       

       

          var CurrencyCode = ['AED', 'ATS', 'AUD', 'BDT', 'BEF', 'BHD', 'BRL', 'CAD', 'CHF', 'CNY',

                      'DEM', 'DKK', 'DZD', 'EGP', 'ESP', 'EUR', 'FRF', 'GBP', 'HKD', 'IDR',

                      'INR', 'ITL', 'JOD', 'JPY', 'KRW', 'KWD', 'LKR', 'LYD', 'MAD', 'MRO',

                      'MYR', 'NLG', 'NOK', 'NZD', 'OMR', 'PHP', 'PKR', 'QAR', 'RSD', 'RUB',

                      'SAR', 'SEK', 'SGD', 'TND', 'TRY', 'USD', 'ZAR', 'Others'];

       

       

       

       

          var CurrencyName = ['dirham', 'schillings', 'dollars', 'taka', 'francs', 'dinar', 'real', 'dollar', 'francs', 'Yuan Renminbi',

                           'Deutsche Mark', 'krone', 'dinar', 'pound', 'pesetas', 'euro', 'francs', 'sterling', 'dollar', 'rupiah',

                           'rupee', 'lira', 'dinar', 'yen', 'won', 'dinar', 'rupee', 'Libyan Dinar', 'dirhams', 'XOF',

                           'ringgit', 'guilders', 'krone', 'dollar', 'omani', 'peso', 'rupee', 'riyal', 'dinar', 'ruble',

                           'riyal', 'krone', 'dollars', 'dinar', 'lira', 'dollar', 'rand', 'Others'];

       

       

          var CurrencySubDivision = ['fils', 'cents', 'cents', 'paisa', 'cents', 'fils', 'centavos', 'cents', 'centimens', 'fen',

                      'cent', 'ore', 'centimes', 'piastres', 'cents', 'cents', 'cents', 'pence', 'cents', 'sen',

                      'paise', 'cents', 'fils', 'cen', 'chon', 'fils', 'cents', 'dirham', 'centimens', 'khoum',

                      'sen', 'cents', 'ore', 'cents', 'baiza', 'centavos', 'paisa', 'dirhams', 'paras', 'kopeks',

                      'halala', 'ore', 'cents', 'millimes', 'kurus', 'cents', 'cents', ''];

       

       

          var x = CurrencyCode.length;

       

       

          for (var i = 0; i < x; i++) {

              if (CurrencyCode[i] == strCurrencyCode) {

       

       

                  if (flgCurType == 1) {

                      return CurrencySubDivision[i];

                  }

                  else

                      return CurrencyName[i];

              }

       

       

          }

       

       

      }

       

       

       

       

      //-----------------------------------------

       

       

       

       

       

       

      //--------------------------------------------------

      function toWords(s) {

          s = s.toString();

          s = s.replace(/[\, ]/g, '');

       

       

          if (s != parseFloat(s)) return 'not a number';

          var x = s.indexOf('.');

          if (x == -1) x = s.length;

          if (x > 15) return 'too big';

          var n = s.split('');

          var str = '';

          var sk = 0;

          for (var i = 0; i < x; i++) {

              if ((x - i) % 3 == 2) {

                  if (n[i] == '1') {

                      str += tn[Number(n[i + 1])] + ' ';

                      i++;

                      sk = 1;

                  }

                  else if (n[i] != 0) {

                      str += tw[n[i] - 2] + ' ';

                      sk = 1;

                  }

              }

              else if (n[i] != 0) {

                  str += dg[n[i]] + ' ';

                  if ((x - i) % 3 == 0) str += 'hundred ';

                  sk = 1;

              }

       

       

              if ((x - i) % 3 == 1) {

                  if (sk) str += th[(x - i - 1) / 3] + ' ';

                  sk = 0;

              }

       

       

          }

       

       

          if (x != s.length) {

              var y = s.length;

              str += 'point ';

              for (var i = x + 1; i < y; i++) str += dg[n[i]] + ' ';

          }

          return str.replace(/\s+/g, ' ');

      }

        • 1. Re: How to convert a decimal number to arabic word
          try67 MVP & Adobe Community Professional

          That is a very complicated task. For starters, the smaller numbers in Arabic need to be written before the larger ones. So "41" is "one-and-forty", not "forty-one"... On top of that there's the issue of encoding the Arabic text in the code.

          This task is also not something that is specific to PDF files, but requires generic JS code.

          You can try searching online and see if there are pre-written functions that do it. Don't expect the people posting here to do it for you, unless you're willing to hire someone to do so.