1
Reply

i have one text box call txtamout. when type any amount in the text box. that amount should be display on the another text box call txtInwords with in words. Ex: if i type 50 on the txtAmount text box. the "Fifty" shoud be appear on the txtInWords. Pls help me as soon as possible. Thanks Regards

mohamed lebbe

mohamed lebbe

16y
4.9k
0
Reply

    use the following code to convert the numeric value to text. On change of numeric value field just call this function to assign the value of text.

    class IntToWord

    {

    static string[] digits = { "", " one", " two", " three", " four", " five",

    " six", " seven", " eight", " nine", " ten",

    " eleven", " twelve", " thirteen", " fourteen", " fifteen",

    " sixteen", " seventeen", " eighteen", " ninteen"};

    static string[] decades = { " twenty", " thirty", " fourty", " fifity", " sixty",

    " seventy", " eighty", " ninety"};

    static string[] decis = { " hundred", " thousand", " lakhs", " crore" };

    static string answer = string.Empty;

    public static string ToWords(int givenNumber)

    {

    if (givenNumber == 0)

    {

    return digits[0];

    }

    else if (givenNumber >= 10000000)

    {

    int crores = givenNumber / 10000000;

    givenNumber %= 10000000;

    return ToWords(crores)+ decis[3] + ToWords(givenNumber) ;

    }

    else if (givenNumber >= 100000)

    {

    int lakhs = givenNumber / 100000;

    givenNumber %= 100000;

    return ToWords(lakhs)+ decis[2]+ ToWords(givenNumber) ;

    }

    else if (givenNumber >= 1000)

    {

    int thousands = givenNumber / 1000;

    givenNumber %= 1000;

    return digits[thousands]+ decis[1] + ToWords(givenNumber) ;

    }

    else if (givenNumber >= 100)

    {

    int hundreds = givenNumber / 100;

    givenNumber %= 100;

    return digits[hundreds]+decis[0] + ToWords(givenNumber) ;

    }

    else if (givenNumber >= 20)

    {

    int tens = givenNumber / 10;

    givenNumber %= 10;

    return decades[tens - 2] + ToWords(givenNumber);

    }

    else if (givenNumber > 10 && givenNumber < 20)

    {

    return digits[givenNumber];

    }

    else

    return digits[givenNumber];

    }

    }