web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

Translate Number Digits to Arabic Words

(0) ShareShare
ReportReport
Posted on by 60

Dear All,

I have a specific field that has a number, what is the best way to convert the digits into words. for example 365 to three hundred and sixty five but in Arabic. what is the best method of achieving that in dynamics 365. if it is done through JavaScript, has such issues been discussed before?

Thanks, 

I have the same question (1)
  • LeoAlt Profile Picture
    16,331 Moderator on at

    Hi partner,

    You could create a custom algorithm with JS to convert digits to words.

    Here are some samples for you.

    https://stackoverflow.com/questions/14766951/convert-digits-into-words-with-javascript

    https://stackoverflow.com/questions/5529934/javascript-numbers-to-words

    https://www.thoughtco.com/how-to-convert-numbers-to-words-with-javascript-4072535

    Regards,

    Leo

  • LeoAlt Profile Picture
    16,331 Moderator on at

    Hi partner,

    Did  my answer helped you?

    If so, please mark my answer as verified to close this thread and help other users with similar issues.

    If you still have any questions about this thread, please feel free to let me konw.

    Regards,

    Leo

  • Suggested answer
    Jomy Jose Profile Picture
    290 on at

    If you want to use C# plugin code use the below logic, below is for English and French, you can change it based on your preferred language.

    public static string ConvertNumberToWords(int pValue, Language pLanguage)

           {

               string strReturn;

               if (pValue < 0)

                   throw new NotSupportedException("Negative numbers not supported");

               else if (pValue == 0)

                   strReturn = pLanguage == Language.English ? "Zero" : "Zéro";

               else if (pValue < 10)

                   strReturn = ConvertDigitToWords(pValue, pLanguage);

               else if (pValue < 20)

                   strReturn = ConvertTeensToWords(pValue, pLanguage);

               else if (pValue < 100)

                   strReturn = ConvertHighTensToWords(pValue, pLanguage);

               else if (pValue < 1000)

                   strReturn = ConvertBigNumberToWords(pValue, 100, "Hundred", pLanguage);

               else if (pValue < 1000000)

                   strReturn = ConvertBigNumberToWords(pValue, 1000, "Thousand", pLanguage);

               else if (pValue < 1000000000)

                   strReturn = ConvertBigNumberToWords(pValue, 1000000, "Million", pLanguage);

               else

                   throw new NotSupportedException("Number is too large!!!");

               if (pLanguage == Language.French)

               {

                   if (strReturn.EndsWith("quatre-vingt"))

                   {

                       //another French exception

                       //strReturn += "s";

                   }

               }

               return strReturn;

           }

           private static string ConvertDigitToWords(int pValue, Language pLanguage)

           {

               switch (pValue)

               {

                   case 0: return "";

                   case 1: return pLanguage == Language.English ? "One" : "Un";

                   case 2: return pLanguage == Language.English ? "Two" : "Deux";

                   case 3: return pLanguage == Language.English ? "Three" : "Trois";

                   case 4: return pLanguage == Language.English ? "Four" : "Quatre";

                   case 5: return pLanguage == Language.English ? "Five" : "Cinq";

                   case 6: return "six";

                   case 7: return pLanguage == Language.English ? "Seven" : "Sept";

                   case 8: return pLanguage == Language.English ? "Eight" : "Huit";

                   case 9: return pLanguage == Language.English ? "Nine" : "Neuf";

                   default:

                       throw new IndexOutOfRangeException($"{pValue} not a digit");

               }

           }

           //assumes a number between 10 & 19

           private static string ConvertTeensToWords(int pValue, Language pLanguage)

           {

               switch (pValue)

               {

                   case 10: return pLanguage == Language.English ? "Ten" : "Dix";

                   case 11: return pLanguage == Language.English ? "Eleven" : "Onze";

                   case 12: return pLanguage == Language.English ? "Twelve" : "Douze";

                   case 13: return pLanguage == Language.English ? "thirteen" : "Treize";

                   case 14: return pLanguage == Language.English ? "Fourteen" : "Quatorze";

                   case 15: return pLanguage == Language.English ? "Fifteen" : "Quinze";

                   case 16: return pLanguage == Language.English ? "Sixteen" : "Seize";

                   case 17: return pLanguage == Language.English ? "Seventeen" : "Dix-sept";

                   case 18: return pLanguage == Language.English ? "Eighteen" : "Dix-huit";

                   case 19: return pLanguage == Language.English ? "Nineteen" : "Dix-neuf";

                   default:

                       throw new IndexOutOfRangeException($"{pValue} not a teen");

               }

           }

           //assumes a number between 20 and 99

           private static string ConvertHighTensToWords(int pValue, Language pLanguage)

           {

               int tensDigit = (int)(Math.Floor((double)pValue / 10.0));

               string tensStr;

               switch (tensDigit)

               {

                   case 2: tensStr = pLanguage == Language.English ? "Twenty" : "Vingt"; break;

                   case 3: tensStr = pLanguage == Language.English ? "Thirty" : "Trente"; break;

                   case 4: tensStr = pLanguage == Language.English ? "Forty" : "Quarante"; break;

                   case 5: tensStr = pLanguage == Language.English ? "Fifty" : "Cinquante"; break;

                   case 6: tensStr = pLanguage == Language.English ? "Sixty" : "Soixante"; break;

                   case 7: tensStr = pLanguage == Language.English ? "Seventy" : "Soixante-dix"; break;

                   case 8: tensStr = pLanguage == Language.English ? "Eighty" : "Quatre-vingt"; break;

                   case 9: tensStr = pLanguage == Language.English ? "Ninety" : "Quatre-vingt-dix"; break;

                   default:

                       throw new IndexOutOfRangeException($"{pValue} not in range 20-99");

               }

               if (pValue % 10 == 0) return tensStr;

               //French sometime has a prefix in front of 1

               string strPrefix = string.Empty;

               if (pLanguage == Language.French && (tensDigit < 8) && (pValue - tensDigit * 10 == 1))

                   strPrefix = "-et";

               string onesStr;

               if (pLanguage == Language.French && (tensDigit == 7 || tensDigit == 9))

               {

                   tensStr = ConvertHighTensToWords(10 * (tensDigit - 1), pLanguage);

                   onesStr = ConvertTeensToWords(10 + pValue - tensDigit * 10, pLanguage);

               }

               else

                   onesStr = ConvertDigitToWords(pValue - tensDigit * 10, pLanguage);

               return tensStr + strPrefix + "-" + onesStr;

           }

           // Use this to convert any integer bigger than 99

           private static string ConvertBigNumberToWords(int pValue, int baseNum, string baseNumStr, Language pLanguage)

           {

               // special case: use commas to separate portions of the number, unless we are in the hundreds

               string separator;

               if (pLanguage == Language.French)

                   separator = " ";

               else

                   separator = (baseNumStr != "Hundred") ? ", " : " ";

               // Strategy: translate the first portion of the number, then recursively translate the remaining sections.

               // Step 1: strip off first portion, and convert it to string:

               int bigPart = (int)(Math.Floor((double)pValue / baseNum));

               string bigPartStr;

               if (pLanguage == Language.French)

               {

                   string baseNumStrFrench;

                   switch (baseNumStr)

                   {

                       case "Hundred":

                           baseNumStrFrench = "Cent";

                           break;

                       case "Thousand":

                           baseNumStrFrench = "Mille";

                           break;

                       case "Million":

                           baseNumStrFrench = "Million";

                           break;

                       case "Billion":

                           baseNumStrFrench = "Milliard";

                           break;

                       default:

                           baseNumStrFrench = "????";

                           break;

                   }

                   if (bigPart == 1 && pValue < 1000000)

                       bigPartStr = baseNumStrFrench;

                   else

                       bigPartStr = ConvertNumberToWords(bigPart, pLanguage) + " " + baseNumStrFrench;

               }

               else

                   bigPartStr = ConvertNumberToWords(bigPart, pLanguage) + " " + baseNumStr;

               // Step 2: check to see whether we're done:

               if (pValue % baseNum == 0)

               {

                   if (pLanguage == Language.French)

                   {

                       if ((bigPart > 1) && (baseNumStr == "Million"))

                       {

                           //in French, a s is required to cent/mille/million/milliard if there is a value in front but nothing after

                           return bigPartStr + "s"; //This is not required as always dirhams is suffixed in the end

                           //return bigPartStr;

                       }

                       else

                           return bigPartStr;

                   }

                   else

                       return bigPartStr;

               }

               else

               {

                   if (pLanguage == Language.French)

                   {

                       if ((bigPart > 1) && (baseNumStr == "Million"))

                       {

                           //in French, a s is required to cent/mille/million/milliard if there is a value in front but nothing after

                           bigPartStr = bigPartStr + "s"; //This is not required as always dirhams is suffixed in the end

                           //return bigPartStr;

                       }

                   }

               }

               // Step 3: concatenate 1st part of string with recursively generated remainder:

               int restOfNumber = pValue - bigPart * baseNum;

               return bigPartStr + separator + ConvertNumberToWords(restOfNumber, pLanguage);

           }

    Please mark as verified if the answer is helpful

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 80

#3
Martin Dráb Profile Picture

Martin Dráb 64 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans