locked
number to word (towords) BUT for arabic language RRS feed

  • Question

  • User-1123701243 posted

    Hi all

    I have to change the total amount from number to words.

    For the English language the function towords() works fine.

    BUT I need to change it into ARABIC language.

    Help is very much appreciated.

    Saturday, January 11, 2014 4:30 AM

Answers

  • User281315223 posted

    Could you be a bit more specific on exactly what you need to do?

    Are you saying that you would need to change something like "42" to "Fourty-two"? I haven't worked with Crystal Reports that deeply, but I'm not sure of something that will do that off the top of my head.

    Obviously in C#, you would use something similar to what was mentioned in this Stack Overflow discussion

    public static string NumberToWords(int number)
    {
        if (number == 0)
            return "zero";
    
        if (number < 0)
            return "minus " + NumberToWords(Math.Abs(number));
    
        string words = "";
    
        if ((number / 1000000) > 0)
        {
            words += NumberToWords(number / 1000000) + " million ";
            number %= 1000000;
        }
    
        if ((number / 1000) > 0)
        {
            words += NumberToWords(number / 1000) + " thousand ";
            number %= 1000;
        }
    
        if ((number / 100) > 0)
        {
            words += NumberToWords(number / 100) + " hundred ";
            number %= 100;
        }
    
        if (number > 0)
        {
            if (words != "")
                words += "and ";
    
            var unitsMap = new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
            var tensMap = new[] { "zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };
    
            if (number < 20)
                words += unitsMap[number];
            else
            {
                words += tensMap[number / 10];
                if ((number % 10) > 0)
                    words += "-" + unitsMap[number % 10];
            }
        }
    
        return words;
    }

    which I suppose could be slightly altered to use Arabic (as long the rules were basically the same). Another alternatively might be to simply convert it to English and then use some kind of translation utility or service to handle the conversion.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 11, 2014 9:10 AM

All replies

  • User281315223 posted

    Could you be a bit more specific on exactly what you need to do?

    Are you saying that you would need to change something like "42" to "Fourty-two"? I haven't worked with Crystal Reports that deeply, but I'm not sure of something that will do that off the top of my head.

    Obviously in C#, you would use something similar to what was mentioned in this Stack Overflow discussion

    public static string NumberToWords(int number)
    {
        if (number == 0)
            return "zero";
    
        if (number < 0)
            return "minus " + NumberToWords(Math.Abs(number));
    
        string words = "";
    
        if ((number / 1000000) > 0)
        {
            words += NumberToWords(number / 1000000) + " million ";
            number %= 1000000;
        }
    
        if ((number / 1000) > 0)
        {
            words += NumberToWords(number / 1000) + " thousand ";
            number %= 1000;
        }
    
        if ((number / 100) > 0)
        {
            words += NumberToWords(number / 100) + " hundred ";
            number %= 100;
        }
    
        if (number > 0)
        {
            if (words != "")
                words += "and ";
    
            var unitsMap = new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
            var tensMap = new[] { "zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };
    
            if (number < 20)
                words += unitsMap[number];
            else
            {
                words += tensMap[number / 10];
                if ((number % 10) > 0)
                    words += "-" + unitsMap[number % 10];
            }
        }
    
        return words;
    }

    which I suppose could be slightly altered to use Arabic (as long the rules were basically the same). Another alternatively might be to simply convert it to English and then use some kind of translation utility or service to handle the conversion.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 11, 2014 9:10 AM
  • User-1123701243 posted

    Thanks Rion

    Am going to try it and make some translation to it.

    It seems to be helpful.

    you will get my feedback after I try it

    Saturday, January 11, 2014 1:51 PM
  • User-578610739 posted

    Hi Human2x,

    There is no direct method to convert english to arabic language.

    You need, eigher cystal report tool or get the value(store value in arabic language in db and show as it is)  from database or as above said rion, use c# code

    for first option , please check this.

    https://scn.sap.com/thread/1794970

    http://scn.sap.com/thread/1317428

    for second option, you have to store in arabic language, and show as it is in crystal report. for label of crystal report , just add arabic font in your pc and select label language to arabic(the same font you have to install in server while deploye)

    for third option, you simple save in english as currently you have done, use XSD database (it is same as our datatable) , store the value in it and pass this XSD to crystal report.

    http://www.codeproject.com/Articles/3836/Crystal-Reports-PUSH-method-using-ASP-NET

    http://forums.asp.net/t/1366069.aspx?XML+Schema+for+Crystal+Reports+

    Monday, January 13, 2014 1:17 AM