Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
For Example :

Rs.12,522,554.25
(Twelve Million Five Hundred and Twenty Two Thousand Five Hundred and Fifty Four and Five Cents Only)


I want to show this in 3 labels as,

label1: Twelve Million Five Hundred and Twenty Two
label2: Thousand Five Hundred and Fifty Four and Twenty
label3: Five Cents Only

*********************************************
if the 1st label exceed it goes to 2nd label,
if 2nd label exceed it goes to 3rd label,
that,s what i want

*********************************************


I am trying to make a cheque writing software,
so i need to show the amount in words as 3 line on the cheque.


Pls its realy needed to my..
anyone can help me.

[Update]
yes, still searching through these topics.
conversion is ok.
bt the spiting part is the problem.
Coz amount in words string continuously goes through 3 labels.
there is the place i am in confused.

if i type a small amount it shows in line 1, when the string gets longer it must show in 1st line and remaining are in line 2.
Posted
Updated 2-Dec-15 22:00pm
v3
Comments
George Jonsson 2-Dec-15 23:02pm    
Where did the 20 cents go? :-)
MBM_HASHEEM 2-Dec-15 23:32pm    
if the 1st label exceed it goes to 2nd label,
if 2nd label exceed it goes to 3rd label,
that,s what i want
George Jonsson 2-Dec-15 23:35pm    
I mean that you have a difference between the numeric value, 12,522,554.25 and the text which ends with 'Five Cents Only'
20 cents are missing. :-)
Patrice T 2-Dec-15 23:50pm    
I guess you missed the end of second line.
George Jonsson 3-Dec-15 0:11am    
Did so. Confusing with the split on several lines.

This furiously look like HomeWork.
You should be able to device something by yourself, it is an easy task.

Quote:
i checked a lot in google, and many sites..couldn't find any solutions
It is simply unbelievable. My Google search gave 4 solutions in the first page of answers.
I guess you really need to learn how to use Google.

Your question is 2 unrelated questions
1) the conversion
2) the lines split
Each question have plenty of solutions on internet. if you look for a ready solution that combine both, it may be more complicated to find.
Can you show what Google search you have done?

[Update]
for the lines split:
All the problem is that chars are variable size.
if you can print the string to a fields with enough height, activating a LineWrap mode should do the trick.
Otherwise, your field should have a method that gives you the width of a string and you see if it fit by comparing with the width of field.
Google with something like string width fit
Need to know more details about the field you copy to.
 
Share this answer
 
v2
Comments
MBM_HASHEEM 3-Dec-15 0:45am    
yes, still searching through these topics.
conversion is ok.
bt the spiting part is the problem.
Coz amount in words string continuously goes through 3 labels.
there is the place i am in confused.

if i type a small amount it shows in line 1, when the string gets longer it must show in 1st line and remaining are in line 2.
Once you have your transliteration to English from Hindi-Urdu currency notation working, why not simply use one Label:

1. Set its 'AutoSize property depending on your UI design.

2. Set its 'TextAlign property depending on your UI design.

3. Assign a single string with line-breaks to it, example:
C#
lbl_IndiaCurrecyFormatToEnglish.Text = "Twelve Million Five Hundred and Twenty Two\nThousand Five Hundred and Fifty Four and Twenty\nFive Cents Only";
 
Share this answer
 
Comments
MBM_HASHEEM 3-Dec-15 1:28am    
its vary bcoz of when i type and amount its converting to string and the string shows in lable1 at the 1st time,if label exceed show in lable2..

i cant exactly tell where the line break comes.its depend on the amount
BillWoodruff 3-Dec-15 2:24am    
Then, use a TextBox with 'WordWrap enabled ?
If you want to use several labels you do it this way.

C#
// The maximum number of characters one label can hold
int maxLen = 50;

// Test string
string text = "Twelve Million Five Hundred and Twenty Two Thousand Five Hundred and Fifty Four and Twenty Five Cents Only";

List<string> parts = new List<string>();
do
{
    if (text.Length < maxLen)
    {
        parts.Add(text);
        break;
    }

    // Find the word break (space) closest to the end of the string
    int len;
    for (len = maxLen; len >= 0; len--)
    {
        if (text[len] == ' ')
            break;
    }

    parts.Add(text.Substring(0, len));

    // Assign the left over of the string
    text = text.Substring(len+1);

} while (true);

label1.Text = (parts.Count > 0) ? parts[0] : "";
label2.Text = (parts.Count > 1) ? parts[1] : "";
label3.Text = (parts.Count > 2) ? parts[2] : "";
 
Share this answer
 
Comments
BillWoodruff 3-Dec-15 4:56am    
Hi George, it appears to me you are basing what goes into the three labels on only the number of characters. Don't you need to consider here the actual rendered width of the characters which will vary with Font, and font size, style, etc. ... assuming the Font is not a fixed-width (monospaced) font ?
try out below method to split string and set in diffrent label

C#
public void SplitString(string Fullstring)
        {
            int count = 0;
            string str1="";
            string str2="";
            string str3="";
            string[] Splittedstring = Fullstring.Split(' ');
            for(int i=0;i<splittedstring.length;i++)>
            {
                count += Splittedstring[i].Length;
                if(count<=50)
                {
                    str1 += " " + Splittedstring[i];
                }
                else if(count >50 && count <=100)
                {
                    str2 += " " + Splittedstring[i];
                }
                else
                {
                    str3 += " " + Splittedstring[i];
                }
            }
            label1.Text = str1;
            label2.Text = str2;
            label3.Text = str3;
        }
 
Share this answer
 
Comments
BillWoodruff 4-Dec-15 2:20am    
It appears to me you are basing what goes into the three labels on only the number of characters. Don't you need to consider here the actual rendered width of the characters which will vary with Font, and font size, style, etc. ... assuming the Font is not a fixed-width (monospaced) font ?
Salman622 5-Dec-15 1:49am    
Its Only a Logic how he can achieve that.
If any problem exists due to font,font-size,style etc he can sort it out by increasing or decreasing the number of character in the label

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900